wrufesh wrufesh - 5 months ago 13
jQuery Question

HTML table find the column number of <td> which is in <tr> with its <td> included in rowspan

I have a html for table like this:

<table>
<tr>
<td rowspan="3">01</td>
<td>02</td>
<td>03</td>
</tr>
<tr>

<td>05</td>
<td>06</td>
</tr>
<tr>
<td>08</td>
<td>09</td>
</tr>
</table>


Now using jQuery:

rows = $('table')find('tr')


The above code will give me all table rows
Now to get first row data:

row_columns = $(row[0]).find('td')


Now I get row_columns elements as follow:

<td rowspan="3">01</td>
<td>02</td>
<td>03</td>


Now similarly for second row:

row_columns = $(row[1]).find('td')


And for this I get:

<td>05</td>
<td>06</td>


Now What I want to do is to find the second row_columns result's column position. That is
Position of

<td>05</td>


is 2 and the position of

<td>06</td>


is 3 when counting of column is started from 1.

How can i find the position likewise.

Prs Prs
Answer

You can get that with $(row[1]).find('td:eq(0)') or $(row[1]).find('td:first-child')

var row = $('table').find('tr');
var row_columns = $(row[1]).find('td:eq(0)');
console.log(row_columns);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td rowspan="3">01</td>
    <td>02</td>
    <td>03</td>
  </tr>
  <tr>

    <td>05</td>
    <td>06</td>
  </tr>
  <tr>
    <td>08</td>
    <td>09</td>
  </tr>
</table>