Read The First Column Values Of A Html Table With Jquery
I got a table:
Solution 1:
var arr = [];
$("#ItemsTable tr").each(function(){
arr.push($(this).find("td:first").text()); //put elements into array
});
See this link for demo:
Solution 2:
You can use map
method:
var arr = $('#ItemsTable tr').find('td:first').map(function(){
return $(this).text()
}).get()
From jQuery map()
documentation:
Description: Pass each element in the current matched set through a function, producing a new jQuery object containing the return values. . As the return value is a jQuery-wrapped array, it's very common to get() the returned object to work with a basic array.
Solution 3:
// iterate over each row
$("#ItemsTable tbody tr").each(function(i) {
// find the first td in the rowvar value = $(this).find("td:first").text();
// display the value in consoleconsole.log(value);
});
Solution 4:
well from what you have, you can use first-child
var td_content = $('#ItemsTable tr td:first-child').text()
// loop the value into an array or list
Solution 5:
http://jsfiddle.net/Shmiddty/zAChf/
var items = $.map($("#ItemsTable td:first-child"), function(ele){
return $(ele).text();
});
console.log(items);
Number | Number2 |
---|
Post a Comment for "Read The First Column Values Of A Html Table With Jquery"