I have written some JavaScript code. It adds new function to NodeList type in this way:
NodeList.prototype.forEach = function(func) {
var len = this.length
for(var i=0;i<len;i++) func(this[i])
}
It is used somewhere else like that:
document.getElementsByTagName("fieldset").forEach(disappearFields)
All is really simple.
It works nice in chrome but firefox gives an error:
document.getElementsByTagName(“fieldset”).forEach is not a function
[Break on this error] document.getElementsByTagName(“fieldset”).forEach(disappearFields)
disappearFields is short function:
function disappearFields(what) {
what.style.display = "none"
}
I have looked for any help in google but according to those information my code should work properly. I am not able to cope with that myself. Any help ‘ll be appreciated.
FireFox recognizes
document.getElementsByTagName("fieldset")as an HTMLCollectionhttps://developer.mozilla.org/en/DOM/HTMLCollection
I think Safari recognizes it as a NodeList and IE as just an object.