Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从 div 中获取所有元素,这id attribute意味着我想做类似的事情:
id attribute
$("div").find("*[id]").each(function() { alert(this.id) });
但这不起作用,有人可以帮我吗?
您的代码工作得很好,但您可以*从选择器中删除。
*
其他有效选项:
$("div").find("[id]").each(function() { alert(this.id) });
现场演示
或这个:
$("div *").filter("[id]").each(function() { alert(this.id) });
$("div [id]").each(function() { alert(this.id) }); // which I think is the best