addEventListener("keydown", myFunction); - Javascript DOM Event

Javascript examples for DOM Event:addEventListener

Description

The onkeydown event occurs when the user is pressing a key.

Summary

Bubbles Yes
Cancelable Yes
Supported HTML tags: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="text" id="demo">

<script>
document.getElementById("demo").addEventListener("keydown", myFunction);

function myFunction() {/*from   w  w  w .j  a  va 2 s.  c o m*/
    document.getElementById("demo").style.backgroundColor = "red";
}
</script>

</body>
</html>

Related Tutorials