[web] using css to change source image

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

is something like this possible?
<html>
<style>
#image
{
src: url(gfk_money_over.gif);
}
</style>

<body>
<img id="image" />
</body>
</html>



Share on other sites
You can't do something like this in CSS. You'll need javascript to do the job:

document.getElementById('image').src = "gfk_money_over.gif";

Share on other sites
Looks to me like you could just create a div with the desired image as a background, but I'm not seeing the advantage of that, as it still isn't dynamic.

Share on other sites
i agree with Kazgoroth.

Share on other sites
Quote:
 Original post by KazgorothLooks to me like you could just create a div with the desired image as a background, but I'm not seeing the advantage of that, as it still isn't dynamic.
You can do this with the image tag as well, as long as you give it an invisible gif or png as a source. Still strange, perhaps the OP could try and explain why he's doing things this way.

Share on other sites
the reason is because my html is dynamic whereas my css is not.
and because this is for a menu, one of the table entries already uses a background image, whereas the header and footer for the table do not.
        generate_menu("menu","menu-header.png","menu-footer.png",\$linkslist);td.menuitems{        background-image: url(menu-bg.png);}

as you can see I want to keep the data in one place (either css file or menu arguments).

using an empty div tag doesn't work, and you also need a fixed image size for transparent image.

it doesn't matter any more though because I've simply inlined the above css data inside the generate_menu function.

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 20
• 12
• 13
• 14
• 84
• Forum Statistics

• Total Topics
632143
• Total Posts
3004416

×