jQuery Keydown Event Method

jQuery keydown event method; In this tutorial, you will learn what is keydown event in jQuery and how to use this keydown event with HTML elements.

jQuery Keydown Event Method with Example

The jQuery “keydown” event occurs when a keyboard key is initially pressed down. Upon pressing a key on the keyboard, the “keydown()” event takes place. Once this event occurs, it triggers the associated function linked with the “keydown()” method for execution.

Syntax of jQuery Keydown Event Method

Here is a syntax of jquery keydown event:

$(selector).keydown()  

This jquery keydown event trigger for the selected elements.

$(selector).keydown(function)  

Parameters of jQuery keydown()

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

Example of jQuery keydown()

Let’s see an example with demonstrate jQuery keydown().

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

In this jquery keydown event, set the background color “red” of an <input> field when a keyboard key is pressed down.

Recommended jQuery Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *