Sepoto Sepoto - 1 month ago 10
jQuery Question

jQuery getting the value of the second through tenth td of the clicked tr in a table. I already have the first

$("#existcustomers tr").click(function () {
var td1 = $(this).children("td").first().text();
alert(td1);
});


I need the value of td2-td10 as well. I can't seem to figure out how to accomplish this. I tried using
.second()
in the same fashion but that seems to be breaking the programming. Does anyone know how this would be accomplished for the following td's?

Answer

To get a specific cell by index, you can use :

$(this).children(":eq(1)")

To get the first 10 children, use :

$(this).children(":lt(10)")

If you want to get the content in separate cells of an array, you can do

var texts = $(this).children(":lt(10)").map(function(){return $(this).text()});

This makes an array like this :

["contentofcell1", "cell2", "3", "cell 4", "five", "six", "sieben", "otto", "neuf", "X"]