开发者

Getting an Id value using a class value using jQuery

开发者 https://www.devze.com 2023-02-06 13:05 出处:网络
I have several divs that I want to work with dynamically. <div class=\"parent-19\" id=\"123\"></div>

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消