tags:

views:

66

answers:

1

any better way to write this ?

$(this).parent().parent().find(" dd ul").toggle();


update..

I am trying to create a dropdown using the script here http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx

however the script works only for one instance of list and my code works good for multiple instances. Just curious if there is another better way to get parent of a parent in jQuery

+4  A: 

You can use closest() method to find the parent dd element and go from there:

$(this).closest('dd').find('ul').toggle();
Lance McNearney
closet method goes through the DOM the opposite way ? I mean from bottom to top ?
atif089
Correct, it finds the first parent that matches the selector going up the DOM.
Lance McNearney
cool.. thanks :)
atif089