Prevent space button from triggering any other button click in jQuery

I also had this problem and after a bit of fiddling found that it's keyup that triggers button clicks. I've made a fiddle that demonstrates this: https://jsfiddle.net/Beppe/o6gfertu/1/. It works in Firefox and Chrome, although in the latter the button changes appearance to look pressed.


Simply use

$(element).blur();

to unfocus any element (like button) when it is focused (like click event for button).


For those who are expecting SPACE in some text input within clickable DIV. Try this:

HTML:

<div id="someClickableDiv" onclick="doSomething()">
    <textarea onkeyup="event.preventDefault()"></textarea>
</div>

Or Angular 6 version:

<div id="someClickableDiv" (click)"doSomething()">
    <textarea (keyup)="$event.preventDefault()"></textarea>
</div>