thead = new Array();
alert(thead.length);
thead = document.getElementsByTagName("th");
alert(thead.length);
thead.pop();
alert(thead.length);
document.getElementsByTagName("th") returns an array of elements, so thead variable should be an array, if so, then why it gives me the error "thead.pop() is not a function"?
getElementsByTagName (docs) does not return an Array, it returns a NodeList. As said by the linked NodeList docs:
NodeList are used very much like arrays and it would be tempting to use Array.prototype methods on them. This is, however, impossible.
There are some Array like things you can do with a NodeList, and you can even .apply some Array.prototype methods to them, but you should read the docs to avoid the "gotchas", especially where problems with the NodeList being "live" could bite you.
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