Event delegation: setting the useCapture parameter of addEventListener() to true - Javascript DOM Event

Javascript examples for DOM Event:onblur

Description

Event delegation: setting the useCapture parameter of addEventListener() to true

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials