View Full Version : onclick Background

02-22-2007, 08:54 PM
I have an input form that has a background image set by default. I need to make it change background on click.

What is the codeof this? (I need something like <input bla blabla onclick="...">)

I looked on google but they all had complicated JS.

Thanks in Advance, Erind

02-22-2007, 09:01 PM

.myBackground { background-image: url("image.png"); }


<input type="" onclick="this.className = 'myBackground';">

If it has another background assigned via something with greater specificity, such as an ID, then you may need to use background-image:&#160;url("image.png")&#160;!important. You could also use this.style.backgroundImage, but I prefer to keep all of my CSS in one place.