Javascript examples for jQuery Method and Property:event.delegateTarget
The event.delegateTarget property returns the element for currently attached event handler .
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.
<!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>