Attach a function to the keydown event: - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:keydown

Description

Attach a function to the keydown event:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials