How do i change an image, which is (inside an anchor) for another image (exactly the same width and height), once it (the anchor) has been clicked? – using CSS
so…
<a href="http://etc.co.uk/"><img src="etc.png"></a>
I want my etc.png to show as a different image once you have clicked the anchor. any ideas? Would LOVE if someone could help me with this
First thing I assume you’re talking about an anchor link or a target blank link – otherwise I don’t see the point of changing the image if the user leave the page.
There is no perfect CSS-only solution for that situation. You could play with the pseudo classes of your link and set your image as background of
a
.HTML :
CSS :
With :active
Pro : accept the background-image property
Cons : lost after the link is opened
With :visited
You can use
:visited
only with few css properties: background-color, color and border / outline color. You could eventually play withbackground-color
and a png file with transparency.One thing to note is that
:visited
is persistent as long it is in the user browser history.With Javascript
The better of course if you can is to use Javascript. You don’t need jQuery for that, this simple line will do the trick:
You can do like this