Javascript examples for DOM Event:onblur
Event delegation: setting the useCapture parameter of addEventListener() to true
<!DOCTYPE html> <html> <body> <form id="myForm"> <input type="text" id="myInput"> </form>//from w w w . j a v a 2 s.c om <script> var x = document.getElementById("myForm"); x.addEventListener("focus", myFocusFunction, true); x.addEventListener("blur", myBlurFunction, true); function myFocusFunction() { document.getElementById("myInput").style.backgroundColor = "yellow"; } function myBlurFunction() { document.getElementById("myInput").style.backgroundColor = ""; } </script> </body> </html>