Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get second td of tr using jquery

Tags:

I'm trying to get td values of tr.. but unfortunately it's not working.. may be there is something wrong

My html looks like

<tr class="dname">      <td>abc</td>       <td>value here</td> </tr> 

My jquery code is

  jQuery(".dname").find("tr td:eq(1)").val(); 

What's wrong in this ?

like image 570
Syed Avatar asked Oct 24 '16 08:10

Syed


People also ask

How to find td in table using jQuery?

jQuery: code to get TD text value on button click. text() method we get the TD value (table cell value). So our code to get table td text value looks like as written below. $(document). ready(function(){ // code to read selected table row cell data (values).


1 Answers

jQuery find() method returns the descendants of the selected element. You are already selecting the <tr> with a class of dname and then trying to find a descendant which is also a <tr>.

https://api.jquery.com/find/

The following should work:

jQuery(".dname").find("td:eq(1)").text(); 

Edit: text() instead of val() as @freedomn-m pointed out

like image 130
samjudson Avatar answered Sep 16 '22 14:09

samjudson