In the jQuery API it states
The click event is only triggered after this exact series of events:
- The mouse button is depressed while the pointer is inside the element.
- The mouse button is released while the pointer is inside the element.
However, I just noticed that in Firefox 39 the event is also triggerd when I select an input button element and then press return or the spacekey. Why is that? are there also other events that trigger the click event?
Here is an example, see the jFiddle. If I press the button with the mouse it changes the color as expected. But it also changes the color if I select the button and press return or spacekey.
<style>
div{
width: 200px;
height: 200px;
background-color: green;
}
.red{
background-color: red;
}
</style>
<input type='button' class='button' value='change color'>
<div></div>
<script>
$(document).ready(function(){
$('.button').click(function(e){
$('div').toggleClass('red');
});
});
</script>