简体   繁体   中英

How to iterate through table with id='test' and get ids of each row inside table?

How to iterate through table with id='test' and get ids of each row inside table using JQuery ? I need to collect ids in array.

I think you're looking for jQuery.map :

var ids = $('table#test tr').map(function() {
   return this.id;
});
var arr = [];
$('#test tr').each(function(){
     arr.push($(this).attr('id'));
});

http://jsfiddle.net/B2jGu/

$('table#test tr').each(function() {    
     alert($(this).attr('id')); //here you can push these id's into an array
});

Use this code:

$("#test tr").each(function(){
    var row_id=$(this).attr("id");
    // Now do something with the row_id variable.
});

Ad@m

var TrIds = [];
$('#TableId tr').each(function() {
   TrIds[] = $(this).id();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM