Can';在jquery中使用.find()无法找到特定的标记

Can';在jquery中使用.find()无法找到特定的标记,jquery,Jquery,我被这个问题压得喘不过气来,我想知道“李”是否有一个孩子“ul”。I控制台(使用附加到“span”元素的onclick事件)列出了“li”(使用.children()方法)和“ul”的所有子级,但当我使用.find()方法时,它返回长度为0的值 这是我的代码: HTML: 这里到底发生了什么?谢谢你的帮助!(jquery newbee)您可以使用$('xx')。find('ul')来查找ul或$('xx')。最近('ul')您的代码太令人讨厌了,这个解决方案是不可伸缩的,但它在本例中起作用,如如

我被这个问题压得喘不过气来,我想知道“李”是否有一个孩子“ul”。I控制台(使用附加到“span”元素的onclick事件)列出了“li”(使用.children()方法)和“ul”的所有子级,但当我使用.find()方法时,它返回长度为0的值

这是我的代码:

HTML:


这里到底发生了什么?谢谢你的帮助!(jquery newbee)

您可以使用
$('xx')。find('ul')
来查找ul或
$('xx')。最近('ul')
您的代码太令人讨厌了,这个解决方案是不可伸缩的,但它在本例中起作用,如如何选择您的
ul

function myFunc(el){
    // Grabs the <span> tag
    var x = $(el).parent().parent();
    // Creates a jQuery object out of the list item above.
    console.log(x)
}
函数myFunc(el){
//抓住标签
var x=$(el.parent().parent();
//从上面的列表项中创建jQuery对象。
console.log(x)
}

var x
xx
是jquery变量,当您在日志中调用
$(xx)
jquery时,当它spect一个string时,最接近的('ul')方法返回li的父ul,如果我想得到li的唯一ul子ul,该怎么办?谢谢大家!$(el)最近的('ul')会得到孩子的,谢谢!我只是错过了一些东西。很好的一天!
function myFunc(el){
     var x = $(el).parent(); //the li
     var xx = $(x).parent().parent(); //the parent the ul 
     console.log($(xx).children()); //ul will be listed here
     console.log($(xx).children().find('ul')); //this return 0 length which I believe ul is not found
}
function myFunc(el){
    // Grabs the <span> tag
    var x = $(el).parent().parent();
    // Creates a jQuery object out of the list item above.
    console.log(x)
}