JQuery - select td value for all tr ​​with class

I have a table

<table> <tr class="PO1"></tr> <tr class="PO2"></tr> <tr class="PO3"></tr> </table> 

How can I skip all tr ​​with class "PO1" and get the value of each value of 'td' ?

 $("table#id tr .PO1").each(function(i) { // how to get the td values?? }); 
+8
jquery
source share
4 answers
 var values = $('table tr.PO1 td').map(function(_, td) { return $(td).text(); }).get(); 

This will create an array with the contents of the text from each td . It is probably best to use a map / object:

 var values = $('table tr.PO1 td').map(function(index, td) { var ret = { }; ret[ index ] = $(td).text(); return ret; }).get(); 
+7
source share

The space in front of .P01 is a violation of your current code.

 $("tr.PO1 td").each(function(i){ $(this).text() }); 
+1
source share

: I removed the space before .PO1 because your tr has class P01

 $("table#id tr.PO1").each(function(i) { $(this).find("td").innerHTMl() //for example }); 
0
source share
 $("table#id tr.PO1").each(function(i) { i.children('td').each(function(tdEL) { // tdEl.val(); }); }); 

Pay attention to the space that I deleted between tr and .PO1. In this case, he will try to find each tr with a child having the class .PO1.

0
source share

All Articles