<?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: Working with Events, part 1</title>
	<atom:link href="http://www.learningjquery.com/2008/03/working-with-events-part-1/feed" rel="self" type="application/rss+xml" />
	<link>http://www.learningjquery.com/2008/03/working-with-events-part-1</link>
	<description>Tips, techniques, and tutorials for the jQuery JavaScript library</description>
	<lastBuildDate>Thu, 11 Mar 2010 20:27:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Patrick P.</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79760</link>
		<dc:creator>Patrick P.</dc:creator>
		<pubDate>Mon, 01 Mar 2010 10:05:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79760</guid>
		<description>Hello,

thank you for this article, which is pretty much the first stuff I read about jquery.

I found jquery while looking for a solution to my jquerylightbox problem: I refresh my &quot;content&quot; div with new content and the lightbox won´t work anymore. So event delegation seems to be the solution, but I am not sure how to set it up.

I need to keep all links within my content div and the tag rel=&quot;shadowbox&quot; binded to the the lightbox:

$(function() {
	$(&#039;a[@rel*=lightbox]&#039;).lightBox(); 

});


A little help please! :)

thank you!</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>thank you for this article, which is pretty much the first stuff I read about jquery.</p>
<p>I found jquery while looking for a solution to my jquerylightbox problem: I refresh my &#8220;content&#8221; div with new content and the lightbox won´t work anymore. So event delegation seems to be the solution, but I am not sure how to set it up.</p>
<p>I need to keep all links within my content div and the tag rel=&#8221;shadowbox&#8221; binded to the the lightbox:</p>
<p>$(function() {<br />
	$(&#8216;a[@rel*=lightbox]&#8216;).lightBox(); </p>
<p>});</p>
<p>A little help please! :)</p>
<p>thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dakin Design &#187; jQuery Event Delegation and Nested Tables</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79676</link>
		<dc:creator>Dakin Design &#187; jQuery Event Delegation and Nested Tables</dc:creator>
		<pubDate>Sat, 06 Feb 2010 23:31:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79676</guid>
		<description>[...] was reading a blog post about jQuery event delegation by Karl Swedberg yesterday. One corner case I found in his examples is dealing with nested DOM [...]</description>
		<content:encoded><![CDATA[<p>[...] was reading a blog post about jQuery event delegation by Karl Swedberg yesterday. One corner case I found in his examples is dealing with nested DOM [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross Dakin</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79675</link>
		<dc:creator>Ross Dakin</dc:creator>
		<pubDate>Sat, 06 Feb 2010 22:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79675</guid>
		<description>Nit: if you had a table within that cell, you might actually be targeting a nested cell.

You would want to find the &quot;highest&quot; td element between the event target and the wrapping delegation element (i.e. the td that&#039;s closest to &quot;this&quot;).

Would this be the best way?
&lt;pre&gt;&lt;code&gt;
$(function() {
    $(&#039;table.outer&#039;).click(function(event) {
        var parentCells = $(event.target).parentsUntil(this).filter(&#039;td&#039;);
        var outermostCell = $.merge($(event.target), parentCells).last();

        // now do something with outermostCell
  });
});

&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Nit: if you had a table within that cell, you might actually be targeting a nested cell.</p>
<p>You would want to find the &#8220;highest&#8221; td element between the event target and the wrapping delegation element (i.e. the td that&#8217;s closest to &#8220;this&#8221;).</p>
<p>Would this be the best way?</p>
<pre><code>
$(function() {
    $('table.outer').click(function(event) {
        var parentCells = $(event.target).parentsUntil(this).filter('td');
        var outermostCell = $.merge($(event.target), parentCells).last();

        // now do something with outermostCell
  });
});

</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Get Started with jQuery &#124; CodeIgniter-jQuery</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79569</link>
		<dc:creator>Get Started with jQuery &#124; CodeIgniter-jQuery</dc:creator>
		<pubDate>Mon, 18 Jan 2010 23:47:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79569</guid>
		<description>[...] Working with Events, part 1 [...]</description>
		<content:encoded><![CDATA[<p>[...] Working with Events, part 1 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Working with Events, part 1 &#124; haojii</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79474</link>
		<dc:creator>Working with Events, part 1 &#124; haojii</dc:creator>
		<pubDate>Thu, 07 Jan 2010 09:17:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79474</guid>
		<description>[...] 原文地址：http://www.learningjquery.com/2008/03/working-with-events-part-1 原文作者:  Karl Swedberg [...]</description>
		<content:encoded><![CDATA[<p>[...] 原文地址：http://www.learningjquery.com/2008/03/working-with-events-part-1 原文作者:  Karl Swedberg [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Swedberg</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79408</link>
		<dc:creator>Karl Swedberg</dc:creator>
		<pubDate>Fri, 18 Dec 2009 18:38:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79408</guid>
		<description>Hi Bob,
Yeah, I really should update the article. Note that it was written before jQuery 1.3, and at the time &lt;code&gt;.closest()&lt;/code&gt; didn&#039;t exist. We&#039;re well aware of the method and have written about it in more recent tutorials.

thanks.</description>
		<content:encoded><![CDATA[<p>Hi Bob,<br />
Yeah, I really should update the article. Note that it was written before jQuery 1.3, and at the time <code>.closest()</code> didn&#8217;t exist. We&#8217;re well aware of the method and have written about it in more recent tutorials.</p>
<p>thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bob</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79407</link>
		<dc:creator>bob</dc:creator>
		<pubDate>Fri, 18 Dec 2009 18:26:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79407</guid>
		<description>A little advice, instead of doing this:


if ($tgt.is(&#039;td&#039;)) {
      $thisCell = $tgt;
 } else if ($tgt.parents(&#039;td&#039;).length) {
      $thisCell = $tgt.parents(&#039;td:first&#039;);
 }

You can simply do this (jQuery 1.3 and above)

$thisCell = $tgt.closest(&#039;td&#039;);

Closest first looks at the initial element to see if it matches the selector, and if it doesn&#039;t goes up through the DOM tree and finds the first element that matches the selector.

Might be a good idea to replace the code in the main article.</description>
		<content:encoded><![CDATA[<p>A little advice, instead of doing this:</p>
<p>if ($tgt.is(&#8216;td&#8217;)) {<br />
      $thisCell = $tgt;<br />
 } else if ($tgt.parents(&#8216;td&#8217;).length) {<br />
      $thisCell = $tgt.parents(&#8216;td:first&#8217;);<br />
 }</p>
<p>You can simply do this (jQuery 1.3 and above)</p>
<p>$thisCell = $tgt.closest(&#8216;td&#8217;);</p>
<p>Closest first looks at the initial element to see if it matches the selector, and if it doesn&#8217;t goes up through the DOM tree and finds the first element that matches the selector.</p>
<p>Might be a good idea to replace the code in the main article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: indialike</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79378</link>
		<dc:creator>indialike</dc:creator>
		<pubDate>Wed, 16 Dec 2009 07:27:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79378</guid>
		<description>Very nice and useful tutorials to web designers,
Thanks for posting.</description>
		<content:encoded><![CDATA[<p>Very nice and useful tutorials to web designers,<br />
Thanks for posting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexey</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79259</link>
		<dc:creator>Alexey</dc:creator>
		<pubDate>Mon, 30 Nov 2009 07:52:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79259</guid>
		<description>I&#039;ve finally figure out the reason why onclick doesn&#039;t work with dynamically added elements. Really usefull article, thanks a lot!</description>
		<content:encoded><![CDATA[<p>I&#8217;ve finally figure out the reason why onclick doesn&#8217;t work with dynamically added elements. Really usefull article, thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fu</title>
		<link>http://www.learningjquery.com/2008/03/working-with-events-part-1/comment-page-1#comment-79159</link>
		<dc:creator>Fu</dc:creator>
		<pubDate>Wed, 11 Nov 2009 01:45:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/03/working-with-events-part-1#comment-79159</guid>
		<description>Your article is very helpful for me. Thanks for sharing</description>
		<content:encoded><![CDATA[<p>Your article is very helpful for me. Thanks for sharing</p>
]]></content:encoded>
	</item>
</channel>
</rss>
