getting the id of a given child, doesnt work in ff but does in safari

L

libsfan01

in firefox the following alert does not get created from my function:

ch = container1.childNodes(0).id;
alert(ch)

can anyone tell why this might not work in firefox but does in safari?

thanks

marc
 
R

RobG

libsfan01 said:
in firefox the following alert does not get created from my function:

ch = container1.childNodes(0).id;

childNodes is a list, not a function - some browsers are confused about
that:

var ch = container1.childNodes[0].id;
 
G

Geoffrey Summerhayes

in firefox the following alert does not get created from my function:

ch = container1.childNodes(0).id;
alert(ch)

can anyone tell why this might not work in firefox but does in safari?

Are you getting an error in the console?
 
A

ASM

Geoffrey Summerhayes a écrit :
Why it could work in Safary I don't know,
but why it doesn't work in FF :
because the first chidNode in FF is an invisible text node (without id)
and anyway ... it is :

ch = container1.childNodes[0];
Are you getting an error in the console?

He can also have a look in Firefox's DOM inspector ( #text )

test :
======
ch = container1.childNodes[0];
alert(ch.nodeName);
 
G

Geoffrey Summerhayes

Geoffrey Summerhayes a écrit :

Why it could work in Safary I don't know,
but why it doesn't work in FF :
because the first chidNode in FF is an invisible text node (without id)
and anyway ... it is :

ch = container1.childNodes[0];

Actually the absence of id wouldn't cause a problem for this,
FF would show 'undefined' in the alert box. Round brackets
as opposed to square definitely are the culprit.
He can also have a look in Firefox's DOM inspector ( #text )

Depends a lot on what container1 is, a text node isn't always
the first child.

But it's always a good idea to learn to use the tools that are
there to make the job easier.
 

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,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top