Image swap

enosh's picture

They have: 2 posts

Joined: Mar 2009

Does anyone know if there is a way to get an image swap without using Javascript?

In other words, could I set it up so when I hover over a link, an image will change to another one in HTML, CSS, or PHP?

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

Yes, there is no need to use javascript for a simple image swap now. All you need is the css :hover pseudo-class. Put your images in as backgrounds, and change them with :hover.

Or did you want to remotely change an image on a different part of a page? I might have seen a CSS example of that somewhere ...

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

You can also use onmouseover/onmouseoff in the tag to change the image or background image source - still using Javascript but you don't need to place code anywhere but the element.

<img src="plainimg.jpg" onmouseover="this.src='overimg.jpg'" onmmouseoff="this.src='plainimg.jpg'" />

SmileyCentral.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.