Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selectors select 2nd cell of 2nd row of 2nd table of a form with specific action attrib

<form action="blah">
  <table>...</table>
  <table>
     <tr>...</tr>
     <tr>  
         <td>...<td>
         <td> **some text that changes** </td>

Given the above html structure, how do i get the text that changes , using jQuery

So i want jquery to search like this: -look for form that has atrribute action="blah" -select the 2nd table of the form -select the 2nd row (tr) of the table -select the 2nd cell (td) of the row -give me the text

This will help me greatly understanding jquery... i'm new to it.

Something like $('form[action="blah"]').tables(2).rows(2).cells(2).text but this is not a valid jquery match

like image 930
vmanta Avatar asked Jan 04 '12 06:01

vmanta


1 Answers

So you want the second table cell in the second table row of the second table? The eq function can make this easy

DEMO

var text = $("table:eq(1) tr:eq(1) td:eq(1)").text();

Also note that you didn't close this table cell correctly:

<td>...<td>

should be

<td>...</td>

EDIT

If there are other tables on the page, and you want to make sure you get the second on in the form, then add the form to your selector:

var text = $("form[action='blah'] table:eq(1) tr:eq(1) td:eq(1)").text();
like image 141
Adam Rackis Avatar answered Nov 15 '22 08:11

Adam Rackis