event.delegateTarget Property - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:event.delegateTarget

Description

The event.delegateTarget property returns the element for currently attached event handler .

Syntax

Parameter Description
event Required. The event parameter comes from the event binding function

The following code shows how to change the background color of the <div> element.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("div").on("click", "button", function(event){
        $(event.delegateTarget).css("background-color", "pink");
    });/*from   w ww . j  a  v a 2s.  co  m*/
});
</script>
</head>
<body>

<div style="background-color:yellow">
  <p>Click the button to change the background color of this div.</p>
  <button>Click me!</button>
</div>

<div style="background-color:red">
  <p>Click the button to change the background color of this div.</p>
  <button>Click me!</button>
</div>

<div style="background-color:blue">
  <p>Click the button to change the background color of this div.</p>
  <button>Click me!</button>
</div>

</body>
</html>

Related Tutorials