In JavaScript, using the addEventListener()
method:
object.addEventListener("focusout",
myScript);
This example uses the addEventListener()
method to attach a "focusout" event to an input element.
Write something in the input field, and then click outside the field to lose focus.
Firefox does not support the onfocusout event.
<!DOCTYPE html> <html> <body> <input type="text" id="fname"> <p id="demo"></p> <script> document.getElementById("fname").addEventListener("focusout", myFunction); function myFunction() {/*from ww w .j a v a 2 s. com*/ document.getElementById("demo").innerHTML = "Input field lost focus."; } </script> </body> </html>
Bubbles: Cancelable: Event type: Supported HTML tags: | Yes No FocusEvent ALL HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|