Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <head> <script> function myFunction(x) { x.style.background = "yellow"; } </script> </head> <body> <h1>JavaScript HTML Events</h1> <h2>The onfocus Attribute</h2> Enter your name: <input type="text" onfocus="myFunction(this)"> <p>When the input field gets focus, a function is triggered which changes the background-color.</p> </body> </html>