开发者

How can I hide a ul inside li?

开发者 https://www.devze.com 2023-01-11 01:46 出处:网络
Please tell me how can I hide ul child element inside each li, by clicking li link. I mean if someone clicks Alink, A1 and A2 hides.

Please tell me how can I hide ul child element inside each li, by clicking li link. I mean if someone clicks Alink, A1 and A2 hides.

This is my HTML code :

[Code missing]

And here is the jQuery code, but it doesn't work :( 开发者_JAVA技巧

$(document).ready(function() {
  $("#ListGrayCircle li").click(function() {
    $(this).find('ul').hide();     
  });
});


Without the html I'll assume that the inner [ul] to be hidden is not within the [a] tag. Your code should run fine if the user clicks the [li] but if it's an [a] link within it it won't. Try:

$(document).ready(function() {
    $("#ListGrayCircle li").click(function() {
        $(this).closest('li').find('ul').hide();
    });
});
0

精彩评论

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