[javascript] Getting text from td cells with jQuery

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?

This question is related to javascript jquery

The answer is


$(document).ready(function() {
  $('td').on('click', function() {
    var value = $this.text();
  });
});

I would give your tds a specific class, e.g. data-cell, and then use something like this:

$("td.data-cell").each(function () {
    // 'this' is now the raw td DOM element
    var txt = $(this).html();
});

You can use .map: http://jsfiddle.net/9ndcL/1/.

// array of text of each td

var texts = $("td").map(function() {
    return $(this).text();
});

$(".field-group_name").each(function() {
        console.log($(this).text());
    });