开发者

Get checkbox's ID

I need to get the ID of checkboxes in a table in the <tbody> section. I have a live(click) function that I want to bring up a popup with the data that i want based in the id in the checkbox.

I want to also allow the system, to have multiple checkboxes checked I want to be able to store the ids in a temp var and the use them as needed and get rid of them as I go thoug开发者_如何学编程h them.


Just get id with .attr:

$("#container input:checkbox").attr("id")

To get an array of checkboxes ids you might use .map function:

var idArr = $("#container input:checkbox").map(function(i, el) { return $(el).attr("id"); }).get();


$("#container input:checkbox") will be a jQuery object of all the checkboxes inside a particular div with an id of container. You can store that value and use it in the future to carry out all sorts of jQuery operations.

If you want to collect all the DOM objects into a separate array, you can just do a .get() on it.

var domObjects = $("#container input:checkbox").get();

If you want to get all the ids into an array, you could do it this way:

var idArray = [];
$("#container input:checkbox").each(function() {
    idArray.push(this.id);
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜