As title suggests I want to know the difference between the change and click event of checkbox (in jQuery)
I have read down the answer to this What the difference between .click and .change on a checkbox
But, its not working for me. change fires even when I hit spaces without losing focus.
Here’s a fiddle demo
Both seems to be working alike. Am I missing something here ?
According to the W3C, the
onclickevent is triggered by the keyboard for accessibility purposes:SCR35: Making actions keyboard accessible by using the onclick event of anchors and buttons
In order to provide a better user experience for those without the use of a mouse, browsers have been developed to fire the
onclickevent even if the click occurs with a keyboard.For this reason, jQuery’s
clickevent will fire even if the checkbox is clicked by using the keyboard’s spacebar.change, obviously, will fire every time the checkbox’s state changes.The checkbox just happens to be the special case where
changeandclickare interchangable, because you can’t fire thechangeevent without also triggeringclick.Of course, the exception to this rule is if you were to use javascript to manually alter the checkbox, such as:
Here’s a demonstration of these different actions: http://jsfiddle.net/jackwanders/MPTxk/1/
Hope this helps.