开发者

Better way to write this?

开发者 https://www.devze.com 2022-12-24 03:46 出处:网络
any better way to write this ? $(this).parent().parent().find(\" dd ul\").toggle(); update.. I am trying to create a dropdown using the script h开发者_如何学Goere

any better way to write this ?

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


update..

I am trying to create a dropdown using the script h开发者_如何学Goere 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


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

$(this).closest('dd').find('ul').toggle();
0

精彩评论

暂无评论...
验证码 换一张
取 消