Friday, November 27, 2009

Re: [jQuery] Problem traversing up list

You don't need to use .parentNode() (vanilla DOM) but .parent() (jQuery flavor).
Then you can access any attribute using .attr().

So instead try : $('#item1-1').parent().attr('id')
This should "tadaaa".

Michel Belleville


2009/11/27 ximo wallas <igguana26@yahoo.com>
Hello there, after too much sarching I have almost give it up with the following.
I have a list with another list nested:
<ul>
    <li id="item1">Item 1
      <ul>
        <li id="item1-1">
          Item 1 - 1
        </li>
        <li id="item1-2">
          Item 1 - 2
        </li>
      </ul>
    </li>
</ul>
Let's say I know the ID of "item1-2" or "item1-1" how can I get the id of the li (item1)?
I have tried with:
alert($('#item1-1').parentNode().id)
But it gaves me an error, maybe just because it is an aberration...



No comments: