I have a table wi开发者_StackOverflow社区th 5 columns,,when I click on first column on the row i need to get the all column row values using jquery?
Thanks
If you'd like your answer in an array:
$('table#mytable td:first-child').click( function(){
var resultArray = $(this).closest('tr').find('td').map( function(){
return $(this).text();
});
// Do something with resultArray
// resultArray is a jQuery object
// resultArray.get() is a plain array. get() can be chained above.
});
$("td:first-child").click(function(){
$(this).closest('tr').find("td").each(function(){
alert(this.innerHTML);
});
});
$("td").click(function(){
$(this).parent().find("td").each(function(){
alert(this + " is one entry of your current row");
});
});
Depends on what is actually IN the table a bit.
var mystuff = $("td").click().parent('tr').children('td').text();
var mystuff = $("td").click().parent('tr').children('td').innerHtml();
accessing them:
mystuff.each(function()
{
//do stuff
};
mystuff.eq(2) // do stuff with second one
精彩评论