Javascript DOM parents? Possibly treeWalker?

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Ok, not sure how to ask this question, I need to write a piece of script that will allow me to change the properties of an object's adjacent sibling:

for example

Code: [ Select ]
<div>
  <a href="javascript:myFunction(this)">link 1</a>
  <a href="javascript:myFunction(this)">link 2</a>
  <a href="javascript:myFunction(this)">link 3</a>
</div>
  1. <div>
  2.   <a href="javascript:myFunction(this)">link 1</a>
  3.   <a href="javascript:myFunction(this)">link 2</a>
  4.   <a href="javascript:myFunction(this)">link 3</a>
  5. </div>


so myFunction will get passed the object, and I want the code to then alter the properties of the containing div.

I need to do this without using names, and I thought that I could use parent but that apparently only applies to frames. I found the treewalker object but I don't really understand how to create one.

Any help anyone?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Wow, this internet search thing is really nifty y'know, all I have to do is type "getting parent element javascript" into google, click a couple of links and I am sorted..... :roll:

If you wondering yourself:
Code: [ Select ]
element.parentNode


IE also supports
Code: [ Select ]
element.parentElement
which is however, non-compliant

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.