开发者

show hide nested ul(s) with jquery?

I have li list with which exapands fine if i click the li are but i want it to expand if i click the link 'a' not the li.

how do i make the jquery below work on the a not the li?

below is the code i have so far:

$("#leftcontent ul li:not(:has(li.current))").find("ul").hide().end() // Hide all other ULs
    .click(function(e) {
        if (开发者_如何转开发this == e.target) {  // if the handler element is where the event originated
            $(this).children('ul').slideToggle('fast');
        }
});


Try this:

$("#leftcontent li > a").click(function() {
    // get the parent <li> of the <a>
    var li = $(this).closest('li');
    // open the child <ul> of the <li>
    li.find(' > ul').slideToggle('fast');
});

Test it here: http://jsfiddle.net/Ye6U5/

And to hide nested uls onload:

$(function() {
    $("#leftcontent li > ul").hide();
});

http://jsfiddle.net/Ye6U5/1/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜