Jump to content

[SOLVED] Changing background image


matfish

Recommended Posts

Hi, Iv got the below code when clicking on an image in a list it changes the background of a div to that image. It simply uses numbers to identify the images,

 

This works fine in FF and IE7, but not IE6 which Im testing:

 

function change_image($id){
document.getElementById('pic_border').style.backgroundImage='url(image_assets/image'+$id+'.jpg)';
}

 

Any ideas why this may not work in IE6-

 

Many thanks

Link to comment
Share on other sites

yup looks like you are mixing up php with javascript, lose the $.

 

I lifted this from my code, runs perfect in ie6 + ff:

document.getElementById('innergraphic').style.backgroundImage= 'url(' + or + ')'; 

-the 'or' is a javascript variable

 

try alerting the 'id' variable, maybe the code that creates it has a cross browser problem.  Also what is the coding of the item with id="pic_border", there can be cross browser compatablilies with the coding of stuff like that.  Like for instance, if it is actually coded name="pic_border", that will work with some browsers and not others.  Some browsers are more sensitive about using the same id= more than once as well.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.