469,272 Members | 1,413 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,272 developers. It's quick & easy.

AjAX, change background image in css dynamically

I will be getting the background url dynamically using ajax and html. I have set an id=boxFooter_002 to my div and have

Expand|Select|Wrap|Line Numbers
  1. .boxFooter_002{position:absolute;right:0px;width:12px;height:12px;background-image:none;filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/DOG.png', sizingMethod='fixed');}
  2. html>body .boxFooter_002{background:url('images/DOG.png') transparent repeat-x 0px 0px;}
  3.  

now the thing is i will need to dynamically change the image url "images/DOG.png" to something else, i have created in ajax a script that gets the new url so how do i change the images/dog.png to what the new url is?
Aug 11 '08 #1
3 4187
acoder
16,027 Expert Mod 8TB
Get the element whose background has to be changed and change the style.backgroundImage property:
Expand|Select|Wrap|Line Numbers
  1. elem.style.backgroundImage = newURL;
Aug 11 '08 #2
Will that also change the url for the IE Fix?

Get the element whose background has to be changed and change the style.backgroundImage property:
Expand|Select|Wrap|Line Numbers
  1. elem.style.backgroundImage = newURL;
Aug 11 '08 #3
acoder
16,027 Expert Mod 8TB
No, probably not. You'd have to change the filter most probably (I don't use filters, so can't say for sure).
Aug 12 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by TheKeith | last post: by
8 posts views Thread by quipo | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.