jQuery: Find the text of a list item that contains a nested ul

后端 未结 7 1600
暖寄归人
暖寄归人 2020-12-10 12:49

I have the following:

  • item1
    • sub1
    • sub2
7条回答
  •  既然无缘
    2020-12-10 13:11

    I think you need to use the each method. so try the following script:

    $(document).ready(function() {
            $('ul').each(function() {
                $(this).find('li').click(function() {
                    var listItem = this;
                    alert($(listItem).text());
                });
            })
        });
    

    with the following markup

    • 1
    • 2
    • 3
    • 4

提交回复
热议问题