Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Click a paragraph to add another. Note that .delegate() attaches a click event handler to all paragraphs - even new ones.</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; p { background:yellow; font-weight:bold; cursor:pointer; padding:5px; } p.over { background: #ccc; } span { color:red; } &lt;/style&gt; &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Click me!&lt;/p&gt; &lt;span&gt;&lt;/span&gt; &lt;script&gt; $("body").delegate("p", "click", function(){ $(this).after("&lt;p&gt;Another paragraph!&lt;/p&gt;"); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>another example </p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; p { color:red; } span { color:blue; } &lt;/style&gt; &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Has an attached custom event.&lt;/p&gt; &lt;button&gt;Trigger custom event&lt;/button&gt; &lt;span style="display:none;"&gt;&lt;/span&gt; &lt;script&gt; $("body").delegate("p", "myCustomEvent", function(e, myName, myValue){ $(this).text("Hi there!"); $("span").stop().css("opacity", 1) .text("myName = " + myName) .fadeIn(30).fadeOut(1000); }); $("button").click(function () { $("p").trigger("myCustomEvent"); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>working of methods for version added: 1.4.2</p> <p>.delegate( selector, eventType, handler(eventObject) ) </p> <p>selector- A selector to filter the elements that trigger the event.</p> <p>eventType- A string containing one or more space-separated JavaScript event types, such as "click" or "keydown," or custom event names.</p> <p>handler(eventObject)- A function to execute at the time the event is triggered.</p> <p>for version added: 1.4.2</p> <p>delegate( selector, eventType, eventData, handler(eventObject) ) </p> <p>selector- A selector to filter the elements that trigger the event.</p> <p>eventType- A string containing one or more space-separated JavaScript event types, such as "click" or "keydown," or custom event names. eventData A map of data that will be passed to the event handler.</p> <p>handler(eventObject)- A function to execute at the time the event is triggered.</p> <p>for version added: 1.4.3</p> <p>delegate( selector, events )</p> <p>selector- A selector to filter the elements that trigger the event.</p> <p>events- A map of one or more event types and functions to execute for them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload