jQuery event.delegateTarget get

Introduction

Show the difference between delegateTarget and currentTarget when delegation occurs

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from  w  w  w. j ava  2  s . co m
<script>
$(document).ready(function(){
  $("body").on("click", "button", function(event){
    document.getElementById("demo").innerHTML = 
         "delegateTarget returns: " + event.delegateTarget.nodeName +
    "<br/>currentTarget returns: " + event.currentTarget.nodeName;
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<button>Test
</button>

</body>
</html>



PreviousNext

Related