Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get table row by using id in html?

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

like image 993
user2767541 Avatar asked Oct 07 '13 12:10

user2767541


People also ask

How do I id a table row in HTML?

An id on a <tr> tag assigns an identifier to the table row. The identifier must be unique across the page.

How do I find row id in a table?

var table = document. getElementById("tableId"); var rowIndex = document. getElementById("b").

Can you give a table an id in HTML?

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.

How do I make a row in a table in HTML?

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.


1 Answers

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.

like image 128
om_deshpande Avatar answered Nov 14 '22 21:11

om_deshpande