Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I have a html page. It contains table. I want to find out a particular cell's index which is in the same position. ie, Here is my table,
<pre lang="HTML">
<table border="1">
   <tr>
      <td rowspan="2">Label 1</td>
      <td rowspan="2">Label 2</td>
      <td colspan="2">Label 3</td>
      <td>Something else</td>
   </tr>
   <tr>
      <td>Item 1</td>
      <td>Item 2</td>
      <td>Item 3</td>
   </tr>
   <tr>
      <td> 1</td>
      <td> 2</td>
      <td> 3</td>
      <td> 4</td>
      <td> 5</td>
   </tr>
</table>
</pre>
Here I want to find the index of the next row's td in the same position of item2.(ie, index of 4) . How it is possible with jQuery? (if click item 2 , i want to alert index of<td>4</td><pre lang="HTML"></pre>)
Posted
Comments
Thanks7872 22-Jul-15 2:57am    
item2 is at index 1,and 4 is at index 3. Correct me if i misunderstood something.
rose38 22-Jul-15 3:01am    
@ Rohan :Your assumption is right.

1 solution

$("table tr td").click(function () {
  var currentIndex = $(this).index();                
  $(this).closest('tr').next().find("td:eq(" + currentIndex + ")")
});

This will give you same index td in next row.

Regards...
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900