Javascript getElementsByTagName broken firefox?

Posted by Sheldon Ross on Stack Overflow See other posts from Stack Overflow or by Sheldon Ross
Published on 2010-06-16T18:37:09Z Indexed on 2010/06/16 18:42 UTC
Read the original article Hit count: 255

I'm getting the weirdest issues with Javascript in Firefox today.

I'm trying to manipulate some table rows, but .getElementsByTagName("tr"); is pulling back junk.

dynamicTable.tableBody = dynamicTable.getElementsByTagName("tbody")[0];
var tableRows = dynamicTable.tableBody.getElementsByTagName("TR");
var actualTableRows = new Array();
for(var i in tableRows) {
    var row = tableRows[i];
    alert(row.tagName);
    if(row.tagName == "TR"){
       actualTableRows.push(row);
    }
}
dynamicTable.bodyRows = actualTableRows;

The puzzling part of course is my temporary hack to fix the error. For some reason .getElementsByTagName("tr") is pulling back some functions also.

Incidently the alert above goes something like this TR TR TR TR undefined undefined undefined.

The code I wanted was something like this

dynamicTable.bodyRows = dynamicTable.tableBody.getElementsByTagName("tr");

But then bodyrows does not contain just tr elements it has the aforementioned junk in it.

Any thoughts?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about tr