<?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: jQuery: passing elements to event handlers</title>
	<atom:link href="http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/feed/" rel="self" type="application/rss+xml" />
	<link>http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/</link>
	<description>a weblog by Tom Armitage</description>
	<lastBuildDate>Tue, 09 Mar 2010 21:07:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jquery for Beginners: Events Part 1 &#171; Asim Sajjad</title>
		<link>http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/comment-page-1/#comment-128174</link>
		<dc:creator>Jquery for Beginners: Events Part 1 &#171; Asim Sajjad</dc:creator>
		<pubDate>Sun, 21 Dec 2008 13:13:07 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/#comment-128174</guid>
		<description>[...] Passing Event Data: Now here is the code to bind the event with object using the bind event handler and also pass the data as well.The code below is taken from Infovore [...]</description>
		<content:encoded><![CDATA[<p>[...] Passing Event Data: Now here is the code to bind the event with object using the bind event handler and also pass the data as well.The code below is taken from Infovore [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/comment-page-1/#comment-98909</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Thu, 07 Aug 2008 09:25:02 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/#comment-98909</guid>
		<description>Sorry you feel that way, Sam. I felt that Vincent&#039;s code stood well on its own: it&#039;s expressive, it&#039;s better code than mine, and it works. I probably should have said &quot;yes, that works&quot;, but I didn&#039;t actually have time to test it. You know, due to being very busy, and my code also working (even if it&#039;s not as expressive).

So, you know: Vincent&#039;s code is good, it works, it&#039;s better than mine; it feels like a nice footnote on the whole endeavour. Anyhow, now I&#039;ve replied. Happy?

If, of course, you&#039;re a spambot, I&#039;m wasting my time writing back to you. But it&#039;s worth a pop.</description>
		<content:encoded><![CDATA[<p>Sorry you feel that way, Sam. I felt that Vincent&#8217;s code stood well on its own: it&#8217;s expressive, it&#8217;s better code than mine, and it works. I probably should have said &#8220;yes, that works&#8221;, but I didn&#8217;t actually have time to test it. You know, due to being very busy, and my code also working (even if it&#8217;s not as expressive).</p>
<p>So, you know: Vincent&#8217;s code is good, it works, it&#8217;s better than mine; it feels like a nice footnote on the whole endeavour. Anyhow, now I&#8217;ve replied. Happy?</p>
<p>If, of course, you&#8217;re a spambot, I&#8217;m wasting my time writing back to you. But it&#8217;s worth a pop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/comment-page-1/#comment-98803</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Wed, 06 Aug 2008 20:31:25 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/#comment-98803</guid>
		<description>I&#039;m getting tired of seeing blog posts where the author doesn&#039;t reply to good comments and questions.  

Great way to make sure whatever readers you do have, stop.</description>
		<content:encoded><![CDATA[<p>I&#8217;m getting tired of seeing blog posts where the author doesn&#8217;t reply to good comments and questions.  </p>
<p>Great way to make sure whatever readers you do have, stop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent Robert</title>
		<link>http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/comment-page-1/#comment-40478</link>
		<dc:creator>Vincent Robert</dc:creator>
		<pubDate>Fri, 10 Aug 2007 12:46:26 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/#comment-40478</guid>
		<description>You actually wanted to toggle the class for every link except the first one (which you toggle twice here). 

Why not just implement directly what you meant ? Here is a simpler version :

&lt;pre&gt;&lt;code&gt;$(document).ready(function() {
	$(&quot;div.container h3 a&quot;)	
		// Add the event handle &quot;onclick&quot;
		.click(function() {
			$(this).parent()
				.next()
					.toggle()
				.end()
				.toggleClass(&quot;open&quot;)
				;
		})
		// Trigger it manually for every link exept the first one
		.filter(&quot;:gt(0)&quot;)
			.click()
		.end()
		;
	};
});
&lt;/pre&gt;&lt;/code&gt;
I didn&#039;t tested but it should work. Hope this helps.</description>
		<content:encoded><![CDATA[<p>You actually wanted to toggle the class for every link except the first one (which you toggle twice here). </p>
<p>Why not just implement directly what you meant ? Here is a simpler version :</p>
<pre><code>$(document).ready(function() {
	$("div.container h3 a")
		// Add the event handle "onclick"
		.click(function() {
			$(this).parent()
				.next()
					.toggle()
				.end()
				.toggleClass("open")
				;
		})
		// Trigger it manually for every link exept the first one
		.filter(":gt(0)")
			.click()
		.end()
		;
	};
});
</code></pre>
<p>I didn't tested but it should work. Hope this helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Linkdumpingâ€”Time Wasted on Binaries</title>
		<link>http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/comment-page-1/#comment-40050</link>
		<dc:creator>Linkdumpingâ€”Time Wasted on Binaries</dc:creator>
		<pubDate>Mon, 06 Aug 2007 23:10:07 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/#comment-40050</guid>
		<description>[...] Here are parts of todays finds, jotted down for later reference: GZIP compression, HTTP Caching, the Pareto principle (plus the wikipedia equivalent), passing elements to event handlers with jQuery, CSS Compress for WordPress, This day in type, Pingdom, We love TXP, Jon Hicks&#8217; google reader theme, lovely inspiring typography works by Craig Ward&#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] Here are parts of todays finds, jotted down for later reference: GZIP compression, HTTP Caching, the Pareto principle (plus the wikipedia equivalent), passing elements to event handlers with jQuery, CSS Compress for WordPress, This day in type, Pingdom, We love TXP, Jon Hicks&#8217; google reader theme, lovely inspiring typography works by Craig Ward&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: malsup</title>
		<link>http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/comment-page-1/#comment-40000</link>
		<dc:creator>malsup</dc:creator>
		<pubDate>Mon, 06 Aug 2007 17:13:52 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2007/08/03/jquery-passing-elements-to-event-handlers/#comment-40000</guid>
		<description>Tom,

You make a great point about dealing with function arguments based on context.  But it is possible to use a single fn for the toggling, although it&#039;s somewhat less intuitive:

&lt;pre&gt;&lt;code&gt;
$(document).ready(function() {
    var $links = $(&quot;div.container h3 a&quot;);
    $links.click(toggleArchiveLinks);
    toggleArchiveLinks($links[0]);
});

function toggleArchiveLinks(event) {
    var element = event.href ? event : this;
    var $p = $(element).parent();
    $p.toggleClass(&quot;open&quot;).next().toggle();
    return false;
}
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Tom,</p>
<p>You make a great point about dealing with function arguments based on context.  But it is possible to use a single fn for the toggling, although it&#8217;s somewhat less intuitive:</p>
<pre><code>
$(document).ready(function() {
    var $links = $("div.container h3 a");
    $links.click(toggleArchiveLinks);
    toggleArchiveLinks($links[0]);
});

function toggleArchiveLinks(event) {
    var element = event.href ? event : this;
    var $p = $(element).parent();
    $p.toggleClass("open").next().toggle();
    return false;
}
</code></pre>
]]></content:encoded>
	</item>
</channel>
</rss>
