javascript - jQuery 获取所有没有分配 id 的元素

标签 javascript jquery

我在父 div 中有一个 div 列表,其中一些有 ID,其他没有(故意),但它们都具有相同的类。如何获取未分配 id 的 div 的列表?

<div class='AllQuestions'>
    <div class='questionList'>Something Something</div>
    <div class='questionList'>Something Something</div>        
    <div class='questionList' id='question-20'>Something Something</div>
    <div class='questionList' id='question-22'>Something Something</div>        
    <div class='questionList'>Something Something</div>
    <div class='questionList' id='question-100'>Something Something</div>
</div>

我知道我可以执行 $('.questionList') 来获取所有 div 的列表,但我不知道如何过滤掉带有 id 的 div。 (此外,由于我随机生成 ID,因此无法可靠地预测它们)

也许一种方法是以某种方式删除带有 id 的内容?

最佳答案

您可以使用$('.AllQuestions .questionList:not([id])')。这应该可以正常工作。

查看这些链接:

关于javascript - jQuery 获取所有没有分配 id 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15576467/

相关文章:

javascript - getBoundingClientRect,内联 SVG 的高度值不正确

javascript - 具有动态键名的 Reactjs setState()?

javascript - 如何观察 iframe 中 DOM 的变化?

javascript - Bootstrap 模态形式,Div 不包含形式

javascript - LinkBut​​ton onclientclick 不起作用

Javascript选择具有最大值的类的元素

javascript - Gulp Browserify ReferenceError : source is not defined

jquery - 如何在href调用div面板的情况下触发事件

jquery - 在 IE9 中重复添加样式时,Div 偶尔会丢失其变换状态

javascript - 注销确认对话框