开发者

jQuery - show only current ul

开发者 https://www.devze.com 2023-03-30 14:20 出处:网络
im new to jQuery and have a slight issue with the following navigation: http://jsfiddle.net/6Dh8j/7/ Essentially, I love the navigation in the Creative Production section of this lovely site: http:/

im new to jQuery and have a slight issue with the following navigation:

http://jsfiddle.net/6Dh8j/7/

Essentially, I love the navigation in the Creative Production section of this lovely site: http://www.gainsburyandwhiting.com > see Portfolio > Fashion Show etc...

I 开发者_如何学JAVAneed to hide the current ul and show a fresh one in its place. At the moment, they show until I un-click the parent.

Any thoughts?

Thanks, Red


You need to hide all the ul elements that are descendant of the siblings of the current ul e.g.

$(this).siblings().find('ul').fadeOut('fast');

This finds each sibling of the clicked ul (all of which are ul in the example) and finds all the ul elements that are withing their bounds and fades them out.

In the context of your code:

$("nav ul li").find("ul").hide().end()
  .click(function(e) {
     if (this == e.target) {
       $(this).siblings().find('ul').fadeOut('fast');
       $(this).children('ul').fadeToggle('fast');    
     }
});
0

精彩评论

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

关注公众号