Jquery select second cell in table
This is the code on the script, i need to get the content from the second cell. The table hasnt got a id but is in a div with the id 'Chat'
The 4th row i can select:
var row = $("#chat tr:nth-child(4)");
But not the second cell:
var cellContent = $("#chat td:nth-child(4)").html();
I cant post images or table tags, so this is a link to开发者_开发百科 the image of the table and its code. http://img577.imageshack.us/img577/8871/chattable.png
Here is a fiddle that hopefully helps your jquery question. http://jsfiddle.net/CrumK/1/
$(document).ready(function() {
// this reads: find the element with ID chat and inside that find every TR element that is the 2nd child of its parent (meaning TABLE).
$("#chat tr:nth-child(2)").css("color", "blue"); // select the second row
// this reads: find the element with ID chat and inside that find every TD element that is the 2nd child of its parent (meaning TR)
$("#chat td:nth-child(2)").css("background", "red"); // select every second TD
// select the second TD of the second TR inside the #chat element
$("#chat tr:nth-child(2) td:nth-child(2)").css("background", "green"); // select the second row
});
精彩评论