[web] using css to change source image

Started by
4 comments, last by Genjix 18 years, 11 months ago
is something like this possible?

<html>
<head>
	<style>
	#image
	{
		src: url(gfk_money_over.gif);
	}
	</style>
</head>

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

Advertisement
You can't do something like this in CSS. You'll need &#106avascript to do the job:

document.getElementById('image').src = "gfk_money_over.gif";
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.

- Jason Astle-Adams

i agree with Kazgoroth.
DinGY
Yesterday is history.Tomorrow is a mystery. Today is a gift"
Quote:Original post by Kazgoroth
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.
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.
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.

This topic is closed to new replies.

Advertisement