开发者

Firefox Javascript: Why does .all not work?

开发者 https://www.devze.com 2023-02-25 01:51 出处:网络
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 unde开发者_如何学Gofined\".

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 unde开发者_如何学Gofined".

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


.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.


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

You may want to look at childNodes instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消