{"id":218,"date":"2023-08-25T17:22:26","date_gmt":"2023-08-25T17:22:26","guid":{"rendered":"\/\/api.jquery.com\/?p=218"},"modified":"2024-04-20T18:06:54","modified_gmt":"2024-04-20T18:06:54","slug":"event.delegateTarget","status":"publish","type":"post","link":"https:\/\/api.jquery.com\/event.delegateTarget\/","title":{"rendered":"event.delegateTarget"},"content":{"rendered":"<article id=\"event-delegateTarget1\" class=\"entry property\"><h2 class=\"section-title\">\n<span>event.delegateTarget<\/span><span class=\"returns\">Returns: <a href=\"http:\/\/api.jquery.com\/Types\/#Element\">Element<\/a><\/span>\n<\/h2>\n<div class=\"entry-wrapper\">\n<p class=\"desc\"><strong>Description: <\/strong>The element where the currently-called jQuery event handler was attached.<\/p>\n<ul class=\"signatures\"><li class=\"signature\"><h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.7\/\">1.7<\/a><\/span>event.delegateTarget<\/h4><\/li><\/ul>\n<div class=\"longdesc\" id=\"entry-longdesc\">\n    <p>This property is most often useful in delegated events attached by <a href=\"\/delegate\/\"><code>.delegate()<\/code><\/a> or <a href=\"\/on\/\"><code>.on()<\/code><\/a>, where the event handler is attached at an ancestor of the element being processed. It can be used, for example, to identify and remove event handlers at the delegation point.<\/p>\n    <p>For non-delegated event handlers attached directly to an element, <code>event.delegateTarget<\/code> will always be equal to <code>event.currentTarget<\/code>.<\/p>\n  <\/div>\n<section class=\"entry-examples\" id=\"entry-examples\"><header><h2>Example:<\/h2><\/header><div class=\"entry-example\" id=\"example-0\">\n<p>When a button in any box class is clicked, change the box's background color to red.<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$( <span class=\"hljs-string\">\".box\"<\/span> ).on( <span class=\"hljs-string\">\"click\"<\/span>, <span class=\"hljs-string\">\"button\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"> event <\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  $( event.delegateTarget ).css( <span class=\"hljs-string\">\"background-color\"<\/span>, <span class=\"hljs-string\">\"red\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div><\/section>\n<\/div><\/article>","protected":false},"excerpt":{"rendered":"<p>The element where the currently-called jQuery event handler was attached.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,31,96],"tags":[],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-event-object","category-events","category-96"],"_links":{"self":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/comments?post=218"}],"version-history":[{"count":2,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":812,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/218\/revisions\/812"}],"wp:attachment":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}