Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <p>Use the addEventListener() method to attach a "keypress" event to an input element.</p> <p>Press a key inside the text field to set a red background color.</p> <input type="text" id="demo"> <script> document.getElementById("demo").addEventListener("keypress", myFunction); function myFunction() { document.getElementById("demo").style.backgroundColor = "red"; } </script> </body> </html>