Click to See Complete Forum and Search --> : image vs getElementById


chong
05-18-2005, 10:25 AM
While coding for a site recently, i encountered a problem while trying to make some mouseover image source changes.

Although
document.getElementById("img1").src = newsrc;
is supposed to be cross compatible, it works only on IE... I couldnt get it to work on Moz5

but
document.image.img1.src = newsrc;
works on both.

doesnt getElementById work the same way on both IE n Moz?

TIA :)

Jona
05-18-2005, 10:29 AM
Are you using ID or NAME or both?

Kor
05-18-2005, 10:36 AM
if you have used name="myname"
document.getElementsByName('myname')[0]
if you have used id="myid"
document.getElementById('myid')

The W3C "unwritten" recomandation" is for using id. id must be unique. name remains to be used only in radio buttons case (case in which document.getElementsByName('radiosname') is the collection of the radio buttons with the same name)...

chong
05-18-2005, 09:03 PM
Thanks! I was using name, will now be using id.

Enlightened :)