How do I get all div IDs in children of “test” div?
The selector below gives only “dog”: i need get “dog”, “cat”, “drig”, for example.
var all = $(".test div").attr("id");
$("div").text(all);
<div class="test">
<div id="dog"></div>
<div id="cat"></div>
<div id="drig"></div>
</div>
Thanks
If you mean all the direct descendants of the element, than you have to change your selector to
$(".test > div")(it’s the child selector). If you want to select all descendants, then you can leave it as it is.Using
.map(), you can create an array of IDs: