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

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

I have the following:

  • item1
    • sub1
    • sub2
7条回答
  •  天涯浪人
    2020-12-10 12:57

    Normal DOM methods allow to access text contents for just one element, rather than jquery:

    $("#list li").click(function() {
        alert($(this)[0].firstChild.textContent)
    });
    

    firstChild in this case is the textNode beneath the li element

提交回复
热议问题