Javascript examples for jQuery Method and Property:keydown
Attach a function to the keydown event:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").keydown(function(){ $("input").css("background-color", "yellow"); });//from w w w . j av a 2 s. co m $("input").keyup(function(){ $("input").css("background-color", "pink"); }); }); </script> </head> <body> <p>Enter your name in the input field.</p> Enter your name: <input type="text"> </body> </html>