Getting an Id value using a class value using jQuery
I have several divs that I want to work with dynamically.
<div class="parent-19" id="123"> </div>
<div class="parent-19" id="124"> </div>
<div class="parent-19" id="125"> </div>
Now, I want to iterate through them like:
$('.parent-19').each(function () {开发者_运维技巧
//Want to load the id into a variable
});
How can I load the id value (e.g. 123) into a variable?
var Id = $(this).???
You don't need to wrap this
with the jQuery object to get the id. Simply do:
var id = this.id;
To get an array of ids:
var ids = $('.parent-19').map(function () {
return this.id;
}).get();
精彩评论