jQuery Keydown Event Example

jQuery keydown event method; Through this tutorial, i am going to show you what is jQuery keydown event and how to use jQuery keydown event with example.

jQuery Keydown Event Example

The Jquery keydown event happens when a keyboard key is pressed down. When you press a key on the keyboard, the keydown () event occurs and once the keydown () event occurs, it executes the function associated with the keydown () method to run.

Syntax jQuery Keydown Event Method

$(selector).keydown()  

This triggers the keydown event for the selected elements.

$(selector).keydown(function)  

Parameters of jQuery Keydown Event Method

ParameterDescription
FunctionIt is an optional parameter. It is executed itself when the keydown event is triggered.

Example jQuery Keydown Event Method

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>  
$(document).ready(function(){  
    $("input").keydown(function(){  
        $("input").css("background-color", "red");  
    });   
});  
</script>  
</head>  
<body>  
Write something: <input type="text">  
</body>  
</html> 

Demo Query Keydown Event Method


Write something:

Recommended jQuery Tutorial

Leave a Comment