Firefox Javascript: Why does .all not work?

狂风中的少年 提交于 2019-12-18 07:04:54

问题


In IE, I can go like:

var x = document.getElementById("header");

alert(x.all[0].tagName);

If I try that in Firefox, I get the error "all is undefined".

What is the Firefox equivalent of IE's .all property?


回答1:


.all is a Microsoft-specific extension to the DOM, and is not supported by any other browsers (except Opera, I believe, who simulate it in order to improve compatibility with sites written for IE).

You can use things like x.children and x.childNodes, or x.getElementById() and x.getElementsByTagName() to reference elements below the current one in the tree, depending on your usage. I suspect in this case x.children is what you're after.




回答2:


all would be the name of an array. It is not a native javascript keyword.

You may want to look at childNodes instead.



来源:https://stackoverflow.com/questions/5666234/firefox-javascript-why-does-all-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!