如果我有以下HTML
<Something attribute="" id="top">
<Something attribute="child" id="child"></Something>
</Something>
我正在尝试获取表示第二个Something
元素的jquery对象。我正在浏览器控制台
$("Something[attribute='child']")
但我似乎每次都得到相同的空数组,但以下工作
$("Something[attribute='']")
这会返回一个表示第一个Something
元素
答案 0 :(得分:0)
这将返回一个具有id(属性)“stack”的div的DOM数组:
var stack = $('div[id=stack]');
var result = " ";
$(stack).each(function(index, element){
result = element.id + result;
});
document.body.innerHTML = result
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<div id="stack"></div>
<div id="stack"></div>
<div id="notstack"></div>
<div id="notstack"></div>