KeyEvent which Property - Check if the user presses the Escape key: - Javascript DOM

Javascript examples for DOM:Key Event

Description

KeyEvent which Property - Check if the user presses the Escape key:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="text" size="50" onkeydown="myFunction(event)">

<script>
function myFunction(event) {//from   www  . j a  v  a  2 s .  co m
    var x = event.which || event.keyCode;
    if (x == 27) {
        console.log("You pressed the Escape key!");
    }
}
</script>

</body>
</html>

Related Tutorials