I am learning jQuery at the moment and have managed to get the below function to work for attaching a keyboard click of 'enter' to a button. Although I can't work out why I need to put anything in the function parameter or at the beginning of the if statement.
For example, why does this work:
$('#enter').keypress(function(event) {
if(event.keyCode == 13) {
$('button').click();
};
});
And this doesn't:
$('#enter').keypress(function() {
if(keyCode == 13) {
$('button').click();
};
});
Here's the HTML:
<input id="enter" placeholder="Enter text"></input>
<button>Get Info</button>
I am struggling to understand the significance of 'event' here.