Is "children" a valid property in Firefox?

T

Todd Cary

In my previous post, I stated that some JavaScript I inherited does not
work in Firefox but does work in IE 6 [in my first post I mixed up the
browsers]. I have now isolated a line where it fails in Firefox; the
line with the property of "children".

function InitMenu()
{
if (document.all["menuBar"])
{
}
else
{
return;
}
document.onclick=HideMenuBar;
var bar = menuBar.children; <-------------<<<
alert("Got to here " + bar.length.toString());

Has anyone else had this problem? Work around?

Many thanks....

Todd
 
M

Martin Honnen

Todd said:
In my previous post, I stated that some JavaScript I inherited does not
work in Firefox but does work in IE 6 [in my first post I mixed up the
browsers]. I have now isolated a line where it fails in Firefox; the
line with the property of "children".

function InitMenu()
{
if (document.all["menuBar"])
{
}
else
{
return;
}
document.onclick=HideMenuBar;
var bar = menuBar.children; <-------------<<<
alert("Got to here " + bar.length.toString());

Has anyone else had this problem? Work around?

Mozilla implements the W3C DOM, it is documented here for the Core:
<http://www.w3.org/TR/DOM-Level-2-Core/>
and for the HTML stuff here:
<http://www.w3.org/TR/DOM-Level-2-HTML/>
Look there if you want to find properties or methods.

As for children, no, in its DOM nodes do not have a property children,
there is a property childNodes however which is similar but not quite
the same (children only covers element nodes but childNodes text nodes
as well).
But IE 5 and later implement much of the W3C DOM too so using childNodes
for instance with Mozilla and IE (5 and later) is possible.
I would strongly suggest if you are writing script nowadays then you try
to use the W3C DOM first as then you can easily cover IE 5/6, Mozilla
1.x and later, Netscape 6/7, Firefox, Opera 7, Konqueror, Safari.
If you stick with stuff coming from the IE 4 DOM (like document.all or
children) then you will find different support in non IE browsers,
sometimes depending on the version or even the rendering mode. For
instance Mozilla versions before Mozilla 1.7.5 or Firefox 1.0 don't
support document.all while by now (only in quirks mode) undetected
document.all support is added. But that only means that someone using
document.all now with Firefox finds an element but then further IE
specific stuff like children on that element fail.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top