javascript - 获取包含特定后代的所有元素

标签 javascript jquery

我正在尝试遍历所有 <li>包含类 .fas 的标签使用 jQuery contains() 方法并对每个方法执行一些操作。

$('li:contains(".fas")').each(function (index) {
    //stuff
}

我不断收到包含 undefined reference 错误。我是否错误地使用了这个方法?

最佳答案

你想要has()

$('li:has(".fas")').each(function (index) {
    //stuff
}

https://api.jquery.com/has/

关于javascript - 获取包含特定后代的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52878221/

相关文章:

jquery - 在 IE8 中使用 CSS 在 <hr> 标签上设置圆 Angular

javascript - 为什么下拉显示点后大写的第一个字符

javascript - Angular数据同步问题

javascript - 如何在同一页面上使用 windows.location.href 将 js 值传递给 php 时停止刷新页面

javascript - 仅在第一个时才考虑动态添加的样式表

javascript - 如何使用 jquery 选择具有或不具有特定 'alt' 属性的图像

jquery - 这里的 .divClicked 是什么?

javascript - 类型错误 : undefined is not a function while returning resource

javascript - 在线谷歌闭包缩小器?

javascript - 包裹多个div