19 Feb jQuery keyup() method
Definition
Use the jQuery keyup() method to fire the keyup event i.e. when a keyboard key is pressed up.
Syntax
The following is the syntax,
$(selector).keyup(func)
The following is the parameter for the keyup method,
- func: When the keyup event is fired, this function runs. This is an optional parameter.
Example
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#input").keyup(function(){
$(this).css("background-color", "yellow");
});
$("#input").keypress(function(){
$(this).css("background-color", "orange");
});
});
</script>
</head>
<body>
<h3>Studyopedia Quiz</h3>
<p>Add you details here to attempt Studyopedia Quiz,</p>
Subject ID: <input id="input" type="number"><br>
<p>Add the details in the field above. The background color will change on pressing any key. On keyup, the color will change again.</p>
</body>
</html>
The following is the output,

The background color will change on pressing any key. On keyup, the color will change again.

No Comments