Getting td value of selected tr in jquery

Below is my table

<table> <tr class=chargeTR> <td id=chargeTD> charge1 </td> </tr class=chargeTR> <td id=chargeTD> charge2 </td> </tr> <table> 

Below is my jQuery call

 $(".chargeTR").each(function() { // this line works fine $.get("process.php", { value: $(this).find("#chargeTD").val(), // I must be doing something wrong here... }, function(theXML){ alert(theXML); }); }); 

I can not get the value of "charge1" and "charge2".

Can someone please correct me on this?

+4
source share
3 answers

use .text() or .html() instead of .val() , since .val is for getting value="" attributes from forms.

+10
source

You may also need to use $ .trim () to get the exact text without spaces.

 $.trim($(this).find("#chargeTD").text()) 
+1
source

This worked from me:

HTML:

 <tr class="" id="tr_id" > <td class="l_id">7283630222</td> </tr> <tr class="" id="tr_id" > <td class="l_id">7276684022</td> </tr> <p id="leadID">-lead id here-</p> 

JQuery

 $(document).ready(function() { $("tr#tr_id").click(function() { $("#leadID").text($(this).find("td.l_id").text()); }); }); 
0
source

Source: https://habr.com/ru/post/1310698/


All Articles