Reputation: 2400
Can somebody tell me how to dynamically change the image of a button while clicking it?
$('.gamebox_minimap_plus').click(function() {
$(this).css("background-image","url('gfx/plus2.png')");
});
It works after a click, not while clicking, and does not come back to plus1.png after I stop clicking.
Upvotes: 2
Views: 736
Reputation: 4275
Use mousedown and mouseup insead of click. Like this:
$('.gamebox_minimap_plus').mousedown(function() { $(this).css("background- image","url('gfx/plus2.png')"); });
$('.gamebox_minimap_plus').mouseup(function() { $(this).css("background-image","url('gfx/plus1.png')"); });
Upvotes: 1
Reputation: 86872
I think you want to use the mousedown and mouseup events.
In addition if you are using jQuery 1.7 or higher you should begin using/getting use to the on() and off() methods.
Upvotes: 4