Michael
Michael

Reputation: 13616

How to get all rows from the table except header row?

I have table created dynamically in JavaScript.

I have this table:

enter image description here

Here the way how I get rows from the table above:

var trows = table.rows;

This way I get all the rows from the table above including the header row. My question is there any way to get all rows from the table except header row?

Upvotes: 1

Views: 2574

Answers (3)

Jayachandran Murugesh
Jayachandran Murugesh

Reputation: 111

before answering your, i would like to suggest to construct the table structure as given below so that you can get result what you exactly needed.

    <table>
      <thead>
       <tr>
          <th>heading</th>
       </tr>
      </thead>
     <tbody id="tableid">
       <tr>
          <td>data1</td>
          <td>data2</td>
       </tr>
     </tbody>
    </table>

And then in your script,now you can get the result as follow

var trows = table.rows;

i hope you might be satisfied with this answer, if not post a question without any hesitation. thank you

Upvotes: 1

Hanky Panky
Hanky Panky

Reputation: 46900

Put all those rows inside <tbody> and put the header inside <thead> Then do

var trows = document.getElementById('tableid').getElementsByTagName('tbody')[0].rows;

Upvotes: 2

KyleK
KyleK

Reputation: 5056

Remove first value of an array with .shift

trows.shift(); // remove first line

Upvotes: 1

Related Questions