- <!--Uses the addEventListener() method to attach a keypress event to an input element.-->
-
- <input type="text" id="demo">
-
- <script>
- document.getElementById("demo").addEventListener("keypress", myFunction);
-
- function myFunction() {
- document.getElementById("demo").style.backgroundColor = "red";
- }
- </script>