Home >>jQuery Tutorial >jQuery keyup() Method

jQuery keyup() Method

jQuery keyup() Method

jQuery keyup() method in jQuery is used to add a function or triggers the keyup event to run when a keyup event occurs.

Syntax:
Trigger the keyup event for the selected elements: $(selector).keyup()
Attach a function to the keyup event: $(selector).keyup(function)

Parameter Values

Parameter Description
function It is optional parameter and is used to specifies the function to run when the keyup event is triggered./td>
Here is an Example of jQuery keyup() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").keydown(function(){
$("input").css("background-color", "orange");
});
$("input").keyup(function(){
$("input").css("background-color", "blue");
});
});
</script>
</head>
<body>
Username: <input type="text">
<p> It will change background color on keydown and keyup and when Enter text in the input field above..</p>
</body>
</html>

Output:
Username:

It will change background color on keydown and keyup and when Enter text in the input field above..