How to get tr count from html table by using Id.Please check my code below
<table id="tableId">
<tr id="a">
<td>a</td>
</tr>
<tr id="b">
<td>b</td>
</tr>
Now I want to find rowNumber by using row Id.for example my rowId is 'b' I want to find rowNumber for this Id.Any one help me
An id on a <tr> tag assigns an identifier to the table row. The identifier must be unique across the page.
var table = document. getElementById("tableId"); var rowIndex = document. getElementById("b").
The id attribute assigns an identifier to the <table> element. The id allows JavaScript to easily access the <table> element. It is also used to point to a specific id selector in a style sheet. Tip: id is a global attribute that can be applied to any HTML element.
The <tr> HTML element defines a row of cells in a table. The row's cells can then be established using a mix of <td> (data cell) and <th> (header cell) elements.
Here you go
var table = document.getElementById("tableId");
var rowIndex = document.getElementById("b").rowIndex;
table.deleteRow(rowIndex);
Added the code for deletion, as requested in the comments below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With