Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  177] [ 3]  / answers: 1 / hits: 177719  / 13 Years ago, wed, november 30, 2011, 12:00:00

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?


More From » jquery

 Answers
7

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.


[#88828] Tuesday, November 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;