In HTML:
This example demonstrates how to assign an "onfocus" event to an input element.
<!DOCTYPE html> <html> <body> Enter your name: <input type="text" id="fname" onfocus="myFunction()"> <script> function myFunction() {/*from w w w .j av a2 s . c om*/ document.getElementById("fname").style.backgroundColor = "red"; } </script> </body> </html>
Bubbles: Cancelable: Event type: Supported HTML tags: | No No FocusEvent ALL HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|