Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old May 15th, 2007, 04:35 PM
libsfan01
Guest
 
Posts: n/a
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

  #2  
Old May 15th, 2007, 05:05 PM
RobG
Guest
 
Posts: n/a

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


libsfan01 wrote:
Quote:
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;


--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
  #3  
Old May 15th, 2007, 05:15 PM
Geoffrey Summerhayes
Guest
 
Posts: n/a

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


On May 15, 11:31 am, libsfan01 <mcyi2...@googlemail.comwrote:
Quote:
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?

---
Geoff

  #4  
Old May 15th, 2007, 05:55 PM
ASM
Guest
 
Posts: n/a

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


Geoffrey Summerhayes a écrit :
Quote:
On May 15, 11:31 am, libsfan01 <mcyi2...@googlemail.comwrote:
Quote:
>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?
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];
Quote:
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);

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
  #5  
Old May 15th, 2007, 06:45 PM
Geoffrey Summerhayes
Guest
 
Posts: n/a

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


On May 15, 12:45 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Quote:
Geoffrey Summerhayes a écrit :
>
Quote:
On May 15, 11:31 am, libsfan01 <mcyi2...@googlemail.comwrote:
Quote:
in firefox the following alert does not get created from my function:
>
Quote:
Quote:
ch = container1.childNodes(0).id;
alert(ch)
>
Quote:
Quote:
can anyone tell why this might not work in firefox but does in safari?
>
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.
Quote:
Quote:
Are you getting an error in the console?
>
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.

---
Geoff

Closed Thread