JavaScript onkeyup Event
You are Here:
JavaScript onkeyup Event
The onkeyup
event occurs when the user releases a key that was previously pressed (on the keyboard).
onkeyup Event as Attribute
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<input type="text" onkeyup="myFunction()">
<script>
function myFunction(){
alert("You released a key inside the input field");
}
</script>
</body>
</html>
Syntax
As Attribute
<element onkeyup = "JavaScript">
As Property
object.onkeyup = function(){
// code
};
Using Event Listener
object.addEventListener("keyup" , myScript);
onkeyup Event as Property
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<input type="text">
<script>
var x = document.getElementsByTagName("input")[0];
function myFunction(){
alert("You released a key inside the input field");
}
x.onkeyup = myFunction;
</script>
</body>
</html>
Using addEventListener() Method
Note: The addEventListener() method is not supported in Internet Explorer 8 and below.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<input type="text">
<script>
var x = document.getElementsByTagName("input")[0];
function myFunction(){
alert("You released a key inside the input field");
}
x.addEventListener("keyup", myFunction);
</script>
</body>
</html>
onkeydown vs onkeypress vs onkeyup
Check out the difference between onkeydown vs onkeypress vs onkeyup in javascript.
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.