Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To get a value of a TD using JQuery

Tags:

jquery

I got a very simple Table with only two rows.
I was thinking what is the best way to get the value from the TD with ID "row2".

<Table id="testing>
<tr>
<th>
</th>
<td id="row1">hello</td>
</tr>
<tr>
<th>
</th>
<td id="row2">world</td>
</tr>
</table>

Here is my attempt:

$(document).ready(function(){ 
      var r=$("#testing":row2).val();
      alert(r);
});

But I couldn't see any message pop up. What shall I do in the JQuery code if I want to specify the Table ID along with the TD ID?

 var r=$("#testing":row2).text();
 var r=$("#testing").children("row2").text();
like image 421
user327712 Avatar asked Jul 31 '10 13:07

user327712


1 Answers

This will do it for you:

  var r = $("#testing #row2").text();
  alert(r);

In action here for your viewing pleasure.

like image 169
Pat Avatar answered Sep 19 '22 21:09

Pat