Forum Moderators: open

Message Too Old, No Replies

Netscape 7 and getElementById

         

Miki

4:16 am on Mar 29, 2004 (gmt 0)

10+ Year Member



Hi all,

Am having some trouble getting getElementById to work in Netscape 7. My code works fine in IE5.5 and IE6, but it keels over in Netscape 7 (and apparently NS6 too)!

I'm trying to get a table cell background image to change using getElementById to grab the reference to the cell:

document.getElementById(cell).background = 'someimage.gif'

Any thoughts?

Purple Martin

5:12 am on Mar 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the id of the element is cell, you need quotes because it's a string:

document.getElementById("cell").background = 'someimage.gif'

If cell is a variable name then you don't need the quotes.

Miki

5:16 am on Mar 29, 2004 (gmt 0)

10+ Year Member



Thanks, Purple Martin. Yes, cell is a variable name representing a string. :)

Purple Martin

5:51 am on Mar 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK. More thoughts...

Try setting the background through the style property:
document.getElementById(cell).style.background = 'url(someimage.gif)'

This should set the CSS background style of your table cell. I remember from past experience that sometimes this sort of thing only works if it already had a value explicitly assigned, so you might need to start with this in your td tag:
<td style="background:url(nothing);">...stuff...</td>
Don't worry about the fact that there is no such file as "nothing", it won't cause any errors.

Miki

7:19 am on Mar 31, 2004 (gmt 0)

10+ Year Member



Yowch, thanks for that, PM, but queerly, it just started working today!

From the looks of things, the Javascript needed to be included in the onmouseover for the TD tag. :)