jQuery event.delegateTarget from click event

Introduction

Show that delegateTarget and currentTarget are equal for directly bound events

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*  w ww.  ja v  a2s . c om*/
<script>
$(document).ready(function(){
  $("button").on("click", 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