The keydown() Event gets executed, when a key (Any key in the keyboard) is pressed.
<html> <head> <title> My First Programme </title> </head> <body> <h1> JQuery </h1> Type Something : <input type = "text"> <script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script> <script> $('input').keydown( function() { $(this).css("background-color", "yellow") }); </script> </body> </html>
So, if you look at the above code, we have an <input> element, that accepts a text.
<input type = "text">
Now, if we take a look at the JQuery statement,
$('input').keydown( function() { $(this).css("background-color", "yellow") });
At first we locate the <input> element,
$('input')
Then we use the keydown() event,
$('input').keydown(...)
And put the function inside keydown() event to change the color of <input> element.
$('input').keydown( function() { $(this).css("background-color", "yellow") });
And the function,
function() { $(this).css("background-color", "yellow") });
Locates the current element (i.e. <input>) using this and changes the color of the <input> element.