I have a table
<table>
<tr class="PO1"></tr>
<tr class="PO2"></tr>
<tr class="PO3"></tr>
</table>
How can I loop through all tr with class "PO1"
and get the value of each 'td'
value?
$("table#id tr .PO1").each(function(i)
{
// how to get the td values??
});
btnSelect',function(){ // get the current row var currentRow=$(this). closest("tr"); var col1=currentRow. find("td:eq(0)"). text(); // get current row 1st TD value var col2=currentRow.
var r=$("#testing":row2). text(); var r=$("#testing"). children("row2"). text();
In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.
var values = $('table tr.PO1 td').map(function(_, td) {
return $(td).text();
}).get();
This would just create an array with the text contents from each td
. Probably a better idea to use a map/object instead:
var values = $('table tr.PO1 td').map(function(index, td) {
var ret = { };
ret[ index ] = $(td).text();
return ret;
}).get();
notice : I removed a space before .PO1 because your tr has class P01
$("table#id tr.PO1").each(function(i)
{
$(this).find("td").innerHTMl() //for example
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With