Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>The modern event handling method:</strong></p> <pre><code>element.addEventListener('click', startDragDrop, false); element.addEventListener('click', spyOnUser, false); </code></pre> <p>The first argument is the event, the second is the function and the third specifies whether to allow event bubbling.</p> <p>From <a href="http://www.quirksmode.org/js/events_advanced.html" rel="nofollow">QuirksMode</a>:</p> <blockquote> <p>W3C’s DOM Level 2 Event specification pays careful attention to the problems of the traditional model. It offers a simple way to register as many event handlers as you like for the same event on one element.</p> <p>The key to the W3C event registration model is the method <code>addEventListener()</code>. You give it three arguments: the event type, the function to be executed and a boolean (true or false) that I’ll explain later on. To register our well known doSomething() function to the onclick of an element you do:</p> </blockquote> <p>Full details here: <a href="http://www.quirksmode.org/js/events_advanced.html" rel="nofollow">http://www.quirksmode.org/js/events_advanced.html</a></p> <p><strong>Using jQuery</strong></p> <p>if you're using jQuery, there is a nice API for event handling:</p> <pre><code>$('#myElement').bind('click', function() { doStuff(); }); $('#myElement').bind('click', function() { doMoreStuff(); }); $('#myElement').bind('click', doEvenMoreStuff); </code></pre> <p>Full details here: <a href="http://api.jquery.com/category/events/" rel="nofollow">http://api.jquery.com/category/events/</a></p>
 

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