Changing the image for a button on hover?
Something like the following will work (although not currently verified), this requires that the alternate image is stored in the custome attribute data-*, so that the script knows where to find it, and then saves the original srcin a similar data-*one to return it to mouseout:
var inputs = document.getElementsByTagName('input');
for (var i = 0, len = inputs.length; i < len; i++) {
input = inputs[i];
input.onmouseover = function(){
this.setAttribute('data-orig-image',this.getAttribute('src'));
this.src = this.getAttribute('data-alt-image');
};
input.onmouseout = function(){
this.src = this.getAttribute('data-orig-image');
};
}
Keep in mind that the above requires yours to inputbe in HTML form:
<input type="image" src="http://path.to/default/image.png" data-alt-image="http://path.to/mouseover/image.png" />
, CSS, , , , input src:
input[type=image] {
background-image: url(http://davidrhysthomas.co.uk/img/dexter.png);
background-repeat: no-repeat;
background-position: 50% 50%;
width: 200px;
height: 185px;
}
input[type=image]:hover,
input[type=image]:active,
input[type=image]:focus {
background-image: url(http://davidrhysthomas.co.uk/img/mandark.png);
}
:
<input type="image" src="derp.png" onMouseOver="this.src='aderp.png'" onMouseOut="this.src='derp.png'">
JSFiddle (demo): http://jsfiddle.net/E6xHr/
, .