document.getElementById(myvar) firefox

L

LargePig

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

The above is a simplification of my code, and i cannot simply do:

function simple_example()
{
thiselement = document.getElementById("element1of12")
}

I have tried:

function simple_example()
{
myarray[0] = "element1of12"
thiselement = document.getElementById(myarray[0].toString())
}

Anyone have any ideas as to how i can make this work?

Thanks

Marc
 
L

LargePig

Hmm.... Something else is wrong, no problem with the function as such.
document.getElementById(array[0]) is not a problem.

Doh..
 
L

LargePig

Hmm.... Something else is wrong, no problem with the function as such.
document.getElementById(array[0]) is not a problem.

Doh..

Yeah....
document.getElementById("something")
works really well in IE even if the element does not have an ID.
Sorry for wasting space on the group with this.....
 
R

RobG

LargePig said:
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.


[...]
 

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,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top