View Full Version : Change the background image of a link

05-08-2007, 05:24 PM
what i am trying to do is simply replace a background image on a link once the link is clicked. Everything works perfectly in firefox, but i keep getting an error in IE7(go figure).

I have been working on this for a few hours now and would really appreciate any help you guys can offer.

The function call is :

function tooth(jaw,sec,tooth){
var obj_t = document.getElementById(jaw + '' + sec + '' + tooth);
if(teeth[jaw][sec][tooth] != 1){
obj_t.style.background="url('images/dot.gif') no-repeat center 4px ;";
teeth[jaw][sec][tooth] = 1;
teeth[jaw][sec][tooth] = 0;

The display/call is:

<a id="u12" title="" href="javascript:tooth('u',1,2)">2</a>

the function should simply get the link by its ID, check a hash variable to see if it has already been selected and change the background accordingly.

IE7 gives me an "Invalid property value" on the line
obj_t.style.background="url('images/dot.gif') no-repeat center 4px ;";

Any help will be greatly appreciated, this has been bothering me for much longer than it should have.

05-08-2007, 05:39 PM
Try removing the semicolon.

obj_t.style.background="url('images/dot.gif') no-repeat center 4px ;";

05-08-2007, 06:39 PM
Wow, i can not believe i wasted that much time for it being semicolon.

Thanks a lot Glenn