I have this code in jQuery:
children('table').children('tbody').children('tr').children('td')
Which gets all table cells for each row. My question is: how can I get the text value in each cell in each row?
Should I use .each()
to loop trough all children('td')
? How can I get the text value of each td
?
$('#mytable tr'). each(function() { var customerId = $(this). find("td:first"). html(); });
$(document). ready(function(){ var r=$("#testing":row2). val(); alert(r); });
jQuery: code to get TD text value on button click.text() method we get the TD value (table cell value). So our code to get table td text value looks like as written below. $(document).
First of all, your selector is overkill. I suggest using a class or ID selector like my example below. Once you've corrected your selector, simply use jQuery's .each() to iterate through the collection:
ID Selector:
$('#mytable td').each(function() { var cellText = $(this).html(); });
Class Selector:
$('.myTableClass td').each(function() { var cellText = $(this).html(); });
Additional Information:
Take a look at jQuery's selector docs.
You can use .map
: http://jsfiddle.net/9ndcL/1/.
// array of text of each td var texts = $("td").map(function() { return $(this).text(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With