Can't seem to get jQuery to change my css.
In my css file this works...
.closed {
background-image: url(http://70.55.103.238/Images/menu-collapsed.gif);
}
I need to be able to change this dynamically with jQuery, so I am calling this in my $(document).ready(function()...
$('.closed').css({ 'background-image' : 'url(http://'+window.location.host+'/Images/menu-collapsed.gif)' });
If it's not obvious, the reason I need to do this is that I cannot use a relative path to the images folder and the host is not a constant.
First question, why is the jquery call not working? If I put an alert like this...
alert('url(http://'+window.location.host+'/Images/menu-collapsed.gif)')
I can see that the URL is correct, and if I enter the url displayed in the alert directly into the address bar I do get the gif. So I am confident that the URL being passed is correct. I must assume that the css is not getting changed.
Second question, is there any way to dynamically get the host url in the .css file so that I do not have use jquery?
Thanks.
Update:
I tried the following just to make it simple..
CSS...
.closed {
background-image: url(../Images/menu-collapsed.gif);
}
javascript...
$('.closed').css({ 'background-image' : 'url(../Images/menu-expanded.gif)' });
Note that the css is set to use menu-collapsed.gif and the javascript changes it to men-expanded.gif. But the image that is displayed is the menu-collapsed.gif.
url(/Images/menu-collapsed.gif)?background-imagevalue is changed to?