Javascript examples for DOM Event:addEventListener
The onfocus event occurs when an element gets focus.
Bubbles | No |
---|---|
Cancelable | No |
Supported HTML tags: | ALL HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
<!DOCTYPE html> <html> <body> <p>This example uses the addEventListener() method to attach a "focus" event to an input element.</p> Enter your name: <input type="text" id="fname"> <script> document.getElementById("fname").addEventListener("focus", myFunction); function myFunction() {//from ww w . j a v a 2 s . c o m document.getElementById("fname").style.backgroundColor = "red"; } </script> </body> </html>