Srinivasan
Srinivasan

Reputation: 12050

table.rows.length is not working in IE11

I have below script in my html page,

var table = document.getElementById(tableID);
var rowCount = table.rows.length;

Its working fine in IE8. But when I use IE11, it is not returning exact row. instead it is just returning "0". But actual row size is "1".

What is the code needs to be replace to make it work.

Upvotes: 0

Views: 2116

Answers (1)

Jamiec
Jamiec

Reputation: 136154

The easiest thing to do, given a reference to the table element is to use querySelectorAll to find the tr within the tbody:

window.onload = function(){
  var table = document.getElementById("tbl");
  console.log(table.querySelectorAll("tbody tr").length);
}
<table id="tbl">
  <tr>
    <td>Row1</td>
  </tr>
  <tr>
    <td>Row2</td>
  </tr>
  <tr>
    <td>Row3</td>
  </tr>
 </table>

Upvotes: 1

Related Questions