Reputation: 8487
I want to get all elements from a div who have id attribute
, means i want to do something like:
$("div").find("*[id]").each(function() { alert(this.id) });
but this is not working , can anybody help me pls?
Upvotes: 3
Views: 3003
Reputation: 150313
Your code works just fine, but you can remove the *
from the selector.
Other valid options:
$("div").find("[id]").each(function() { alert(this.id) });
Or this:
$("div *").filter("[id]").each(function() { alert(this.id) });
Or this:
$("div [id]").each(function() { alert(this.id) }); // which I think is the best
Upvotes: 8