Re: document.getElementById(myvar) firefox
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: document.getElementById(myvar) firefox

From: RobG <rgqld@iinet.net.au>
Date: Tue Nov 22 2005 - 22:25:52 CET

LargePig wrote:
> I have some code that works in IE:
>
> function simple_example()
> {
> myarray[0] = "element1of12"
> thiselement = document.getElementById(myarray[0])
> }
>
> But it does not work in firefox, returns 'null'.

myarray should be declared as an array prior to trying to use it as one.
  myarray and thiselement are globals, are they being affected by events
elsewhere in your code?

Try this test:

   <div id="element1of12">element1of12</div>

   <script type="text/javascript">

   function simple_example()
   {
     var myarray = ['element1of12'];
     var thiselement = document.getElementById(myarray[0]);
     if (thiselement){
       alert( thiselement && thiselement.nodeName );
     }
   }

   </script>

An element with an ID of 'element1of12' must exist before you try to get
a reference to it.

[...]

-- 
Rob
Received on Sat Dec 3 04:28:19 2005