<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Aaron Newton&#8217;s Event Delegation for MooTools</title>
	<atom:link href="http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/</link>
	<description>Sharing what I know and learn about CSS, MooTools, Javascript, PHP and etc.</description>
	<lastBuildDate>Tue, 31 Jan 2012 09:41:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Aaron Newton</title>
		<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/comment-page-1/#comment-6316</link>
		<dc:creator>Aaron Newton</dc:creator>
		<pubDate>Sat, 25 Jul 2009 02:56:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=252#comment-6316</guid>
		<description>Um. Thanks Oliver.</description>
		<content:encoded><![CDATA[<p>Um. Thanks Oliver.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Nassar</title>
		<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/comment-page-1/#comment-6314</link>
		<dc:creator>Oliver Nassar</dc:creator>
		<pubDate>Sat, 25 Jul 2009 02:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=252#comment-6314</guid>
		<description>For me, it&#039;s not so much about the speed enhancement. I&#039;m digging this approach cause it&#039;s makes things simpler. Most ajax these days is about adding dynamically some content from the db, whether it&#039;s a new comment, tag, etc. Using event delegation makes the overhead for this kind of action virtually non-existent.

I love you Aaron.</description>
		<content:encoded><![CDATA[<p>For me, it&#8217;s not so much about the speed enhancement. I&#8217;m digging this approach cause it&#8217;s makes things simpler. Most ajax these days is about adding dynamically some content from the db, whether it&#8217;s a new comment, tag, etc. Using event delegation makes the overhead for this kind of action virtually non-existent.</p>
<p>I love you Aaron.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/comment-page-1/#comment-132</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Fri, 26 Dec 2008 04:39:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=252#comment-132</guid>
		<description>Running the selector on each event is the only way to ensure that the document&#039;s current content is being used. If you cached the $$ value, you wouldn&#039;t get any new items of that type (which is a big value in delegation). The other thing is that you have to check the children of that element for the event because the target might not be the one you&#039;re after. If you have a link tag with a bold tag, the target is the bold tag inside the link (the bottom most element). In order to know that they clicked a link, you must test the link to see if the target is a child.

This is still better than attaching the logic to every link to the page on startup. If you have a highly dynamic page (lots of javascript) you&#039;ll have a lot of startup logic that&#039;s setting up search forms, links, effects, etc. You can lower that startup cost dramatically with delegation. The selector taken on its own is very fast - milliseconds - it&#039;s when you stack them up with dozens of startup methods that the page starts to suffer.</description>
		<content:encoded><![CDATA[<p>Running the selector on each event is the only way to ensure that the document&#8217;s current content is being used. If you cached the $$ value, you wouldn&#8217;t get any new items of that type (which is a big value in delegation). The other thing is that you have to check the children of that element for the event because the target might not be the one you&#8217;re after. If you have a link tag with a bold tag, the target is the bold tag inside the link (the bottom most element). In order to know that they clicked a link, you must test the link to see if the target is a child.</p>
<p>This is still better than attaching the logic to every link to the page on startup. If you have a highly dynamic page (lots of javascript) you&#8217;ll have a lot of startup logic that&#8217;s setting up search forms, links, effects, etc. You can lower that startup cost dramatically with delegation. The selector taken on its own is very fast &#8211; milliseconds &#8211; it&#8217;s when you stack them up with dozens of startup methods that the page starts to suffer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony</title>
		<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/comment-page-1/#comment-131</link>
		<dc:creator>Tony</dc:creator>
		<pubDate>Fri, 26 Dec 2008 03:16:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=252#comment-131</guid>
		<description>&quot;To do this, it must run the same selector that the other example runs ($$(’a&#039;)) and then compare the element clicked with the elements in the selector *and their children*.&quot;

That&#039;s a shame it has to run the $$ function again.  Seems like it would be a lot faster otherwise.  I wonder if there is a way to avoid this, like maybe by using the event target?
...such as:
$(document).addEvent(&#039;mouseover&#039;, function(e,b){   
   if(e.target.nodeName==?){
      //do something cool
   }
} );</description>
		<content:encoded><![CDATA[<p>&#8220;To do this, it must run the same selector that the other example runs ($$(’a&#8217;)) and then compare the element clicked with the elements in the selector *and their children*.&#8221;</p>
<p>That&#8217;s a shame it has to run the $$ function again.  Seems like it would be a lot faster otherwise.  I wonder if there is a way to avoid this, like maybe by using the event target?<br />
&#8230;such as:<br />
$(document).addEvent(&#8216;mouseover&#8217;, function(e,b){<br />
   if(e.target.nodeName==?){<br />
      //do something cool<br />
   }<br />
} );</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/comment-page-1/#comment-130</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Thu, 25 Dec 2008 21:25:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=252#comment-130</guid>
		<description>The speed increase is really a trade off. You are taking the startup costs for your page and shifting the cost to only when the action is performed.

Let&#039;s say that you have a page full of links as in the code example above and there are 100 links. You call addEvent on each of these and you run the selector ($$(&#039;a&#039;)). This isn&#039;t terribly expensive (but you may have a lot of stuff like this going on). When your page loads, this code runs and it creates a demand on the client to process your code immediately. When a user clicks a link, your method is executed immediately and quickly.

Now consider delegation. On startup, you attach an event to the parent (doc.body or something). This is one instruction and it&#039;s nearly instantaneous. Later, a user clicks the document somewhere - anywhere. Now the delegated method fires and the plugin has to see if the user clicked a link and, if so, fire your event. To do this, it must run the same selector that the other example runs ($$(&#039;a&#039;)) and then compare the element clicked with the elements in the selector *and their children*. This makes for a relatively expensive operation, but there&#039;s two big benefits: 1) you only run this code if the user performs the behavior and 2) if the document has changed (new links are added, for instance) you don&#039;t have to attach more events to the new elements.

So the trade off is a faster start-up that doesn&#039;t need to be managed whenever the content changes in return for a slower event-time. Given that the user may never perform the event in question and given that we tend to put a lot of demand on the client at startup time, the benefit is usually worth it when you have a lot of objects you need to attach events to. It doesn&#039;t make sense for attaching it to a specific dom element - for that you&#039;d just use addEvent.

~~~~~~~~~~~~~~~~~~~~~~~~~

All that said, I actually removed this plugin temporarily. See my post here:

http://www.clientcide.com/code-releases/thoughts-on-element-delegation/</description>
		<content:encoded><![CDATA[<p>The speed increase is really a trade off. You are taking the startup costs for your page and shifting the cost to only when the action is performed.</p>
<p>Let&#8217;s say that you have a page full of links as in the code example above and there are 100 links. You call addEvent on each of these and you run the selector ($$(&#8216;a&#8217;)). This isn&#8217;t terribly expensive (but you may have a lot of stuff like this going on). When your page loads, this code runs and it creates a demand on the client to process your code immediately. When a user clicks a link, your method is executed immediately and quickly.</p>
<p>Now consider delegation. On startup, you attach an event to the parent (doc.body or something). This is one instruction and it&#8217;s nearly instantaneous. Later, a user clicks the document somewhere &#8211; anywhere. Now the delegated method fires and the plugin has to see if the user clicked a link and, if so, fire your event. To do this, it must run the same selector that the other example runs ($$(&#8216;a&#8217;)) and then compare the element clicked with the elements in the selector *and their children*. This makes for a relatively expensive operation, but there&#8217;s two big benefits: 1) you only run this code if the user performs the behavior and 2) if the document has changed (new links are added, for instance) you don&#8217;t have to attach more events to the new elements.</p>
<p>So the trade off is a faster start-up that doesn&#8217;t need to be managed whenever the content changes in return for a slower event-time. Given that the user may never perform the event in question and given that we tend to put a lot of demand on the client at startup time, the benefit is usually worth it when you have a lot of objects you need to attach events to. It doesn&#8217;t make sense for attaching it to a specific dom element &#8211; for that you&#8217;d just use addEvent.</p>
<p>~~~~~~~~~~~~~~~~~~~~~~~~~</p>
<p>All that said, I actually removed this plugin temporarily. See my post here:</p>
<p><a href="http://www.clientcide.com/code-releases/thoughts-on-element-delegation/" rel="nofollow">http://www.clientcide.com/code-releases/thoughts-on-element-delegation/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony</title>
		<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/comment-page-1/#comment-115</link>
		<dc:creator>Tony</dc:creator>
		<pubDate>Wed, 24 Dec 2008 20:29:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=252#comment-115</guid>
		<description>&quot;I’m really curious how fast it is though. Time to do a couple console.profile() to log the times.&quot;

So how much faster is it then?</description>
		<content:encoded><![CDATA[<p>&#8220;I’m really curious how fast it is though. Time to do a couple console.profile() to log the times.&#8221;</p>
<p>So how much faster is it then?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

