<?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: $(elem).with();</title>
	<atom:link href="http://james.padolsey.com/javascript/jquery-with-method/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.padolsey.com/javascript/jquery-with-method/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 02 Feb 2012 18:03:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2580</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 07 Jan 2009 23:57:02 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2580</guid>
		<description>Hi John!

Thanks for clearing that up! I do understand why you removed it, although it does seem odd that it wasn&#039;t used a lot, - probably not because it wasn&#039;t useful but because people simply didn&#039;t know it was there. As you know, the same functionality can be achieved in numerous other ways so I guess people didn&#039;t even bother enquiring.

BTW, awesome work on Sizzle, it rules! :)</description>
		<content:encoded><![CDATA[<p>Hi John!</p>
<p>Thanks for clearing that up! I do understand why you removed it, although it does seem odd that it wasn&#8217;t used a lot, &#8211; probably not because it wasn&#8217;t useful but because people simply didn&#8217;t know it was there. As you know, the same functionality can be achieved in numerous other ways so I guess people didn&#8217;t even bother enquiring.</p>
<p>BTW, awesome work on Sizzle, it rules! <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marin</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2579</link>
		<dc:creator>Marin</dc:creator>
		<pubDate>Wed, 07 Jan 2009 23:51:40 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2579</guid>
		<description>comments are ok now. Great blog btw :)</description>
		<content:encoded><![CDATA[<p>comments are ok now. Great blog btw <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Resig</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2578</link>
		<dc:creator>John Resig</dc:creator>
		<pubDate>Wed, 07 Jan 2009 23:10:41 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2578</guid>
		<description>@Dave, James: To clarify: .end() has been in jQuery since the very beginning, as has some form of a stack (although it was definitely clarified in jQuery 1.0, back in 2006).

I, personally, added in the .find(&quot;foo&quot;, function(){}) syntax because I liked - for the same reasons that you did - but after a while it became apparent that 1) I was the only one using it and 2) That it made a large number of methods very sloppy and ambiguous.

We can certainly look at adding it back in some day - but I&#039;m just not seeing it, right now.</description>
		<content:encoded><![CDATA[<p>@Dave, James: To clarify: .end() has been in jQuery since the very beginning, as has some form of a stack (although it was definitely clarified in jQuery 1.0, back in 2006).</p>
<p>I, personally, added in the .find(&#8220;foo&#8221;, function(){}) syntax because I liked &#8211; for the same reasons that you did &#8211; but after a while it became apparent that 1) I was the only one using it and 2) That it made a large number of methods very sloppy and ambiguous.</p>
<p>We can certainly look at adding it back in some day &#8211; but I&#8217;m just not seeing it, right now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2172</link>
		<dc:creator>James</dc:creator>
		<pubDate>Thu, 01 Jan 2009 11:54:39 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2172</guid>
		<description>Thanks Dave, that code will definitely come in handy! It still doesn&#039;t make sense why they got rid of it though, it wouldn&#039;t have done any harm to leave it there. Continually using &#039;end()&#039; just seems so pointless...</description>
		<content:encoded><![CDATA[<p>Thanks Dave, that code will definitely come in handy! It still doesn&#8217;t make sense why they got rid of it though, it wouldn&#8217;t have done any harm to leave it there. Continually using &#8216;end()&#8217; just seems so pointless&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2121</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Wed, 31 Dec 2008 17:29:14 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2121</guid>
		<description>The old jQuery methods returned the original elements if you provided a function, since the function had already processed the found/filtered ones. It looks like they were removed in 1.1, January 2007. I think that was the version where the stack and .end() was introduced so maybe that&#039;s why it was considered expendable.

If you wanted to get that functionality for all methods you could do something like this:
&lt;pre lang=&quot;javascript&quot;&gt;
$().using(&quot;children&quot;, &quot;li&quot;, function() { });
&lt;/pre&gt;
The first arg is the name of the jQuery method you want to use, followed by its arguments (if any) and finally the function to be applied to the filtered elements. A simple implementation:
&lt;pre lang=&quot;javascript&quot;&gt;
$.fn.using = function(/*method, args, fn*/){
	var ap = Array.prototype, args = arguments,
		method = ap.shift.call(args), fn = ap.pop.call(args);
	return this[method].apply(this, args).each(fn).end();
};
&lt;/pre&gt;
Hilarity ensues if the method isn&#039;t one that requires an .end() or if there aren&#039;t enough arguments.</description>
		<content:encoded><![CDATA[<p>The old jQuery methods returned the original elements if you provided a function, since the function had already processed the found/filtered ones. It looks like they were removed in 1.1, January 2007. I think that was the version where the stack and .end() was introduced so maybe that&#8217;s why it was considered expendable.</p>
<p>If you wanted to get that functionality for all methods you could do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">using</span><span class="br0">&#40;</span><span class="st0">&quot;children&quot;</span><span class="sy0">,</span> <span class="st0">&quot;li&quot;</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>The first arg is the name of the jQuery method you want to use, followed by its arguments (if any) and finally the function to be applied to the filtered elements. A simple implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span class="me1">fn</span>.<span class="me1">using</span> <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="co2">/*method, args, fn*/</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
	<span class="kw2">var</span> ap <span class="sy0">=</span> Array.<span class="me1">prototype</span><span class="sy0">,</span> args <span class="sy0">=</span> arguments<span class="sy0">,</span>
		method <span class="sy0">=</span> ap.<span class="me1">shift</span>.<span class="me1">call</span><span class="br0">&#40;</span>args<span class="br0">&#41;</span><span class="sy0">,</span> fn <span class="sy0">=</span> ap.<span class="me1">pop</span>.<span class="me1">call</span><span class="br0">&#40;</span>args<span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">return</span> <span class="kw1">this</span><span class="br0">&#91;</span>method<span class="br0">&#93;</span>.<span class="me1">apply</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> args<span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span>fn<span class="br0">&#41;</span>.<span class="me1">end</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span></pre></div></div>

<p>Hilarity ensues if the method isn&#8217;t one that requires an .end() or if there aren&#8217;t enough arguments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2094</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 31 Dec 2008 09:48:59 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2094</guid>
		<description>Dave, that was my original concern; about &quot;with&quot; being a reserved word, but I didn&#039;t think it mattered when used as a property/method name - it seems to work, although admittedly I haven&#039;t yet tested it in older browsers. If not, then it can just be renamed, I only called it &quot;with&quot; because that seemed to make the most sense. I wasn&#039;t aware that jQuery originally had this functionality under the &#039;find&#039; method; I can&#039;t imagine why they&#039;ve removed it...

It&#039;s easy enough to bring back though:

&lt;pre lang=&quot;javascript&quot;&gt;
$.fn.oFind = $.fn.find;
$.fn.find = function(){
    var a = arguments;
    return $.isFunction(a[1]) ?
        // If a function is passed don&#039;t return
        // elems, just perform the action on them:
        this.each(function(){
            $(a[0],this).each(a[1]);
        })
        : this.oFind.apply(this,a);
}
&lt;/pre&gt;

The problem now is that it doesn&#039;t quite make sense... should it return the original element or the new-found elements? The point in the &quot;with&quot; method was that it didn&#039;t change the subject of the chain...</description>
		<content:encoded><![CDATA[<p>Dave, that was my original concern; about &#8220;with&#8221; being a reserved word, but I didn&#8217;t think it mattered when used as a property/method name &#8211; it seems to work, although admittedly I haven&#8217;t yet tested it in older browsers. If not, then it can just be renamed, I only called it &#8220;with&#8221; because that seemed to make the most sense. I wasn&#8217;t aware that jQuery originally had this functionality under the &#8216;find&#8217; method; I can&#8217;t imagine why they&#8217;ve removed it&#8230;</p>
<p>It&#8217;s easy enough to bring back though:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span class="me1">fn</span>.<span class="me1">oFind</span> <span class="sy0">=</span> $.<span class="me1">fn</span>.<span class="me1">find</span><span class="sy0">;</span>
$.<span class="me1">fn</span>.<span class="me1">find</span> <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="kw2">var</span> a <span class="sy0">=</span> arguments<span class="sy0">;</span>
    <span class="kw1">return</span> $.<span class="me1">isFunction</span><span class="br0">&#40;</span>a<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">?</span>
        <span class="co1">// If a function is passed don't return</span>
        <span class="co1">// elems, just perform the action on them:</span>
        <span class="kw1">this</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
            $<span class="br0">&#40;</span>a<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">,</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span>a<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span><span class="br0">&#41;</span>
        <span class="sy0">:</span> <span class="kw1">this</span>.<span class="me1">oFind</span>.<span class="me1">apply</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span>a<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>The problem now is that it doesn&#8217;t quite make sense&#8230; should it return the original element or the new-found elements? The point in the &#8220;with&#8221; method was that it didn&#8217;t change the subject of the chain&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2081</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Wed, 31 Dec 2008 02:10:19 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2081</guid>
		<description>I like the idea, but &quot;with&quot; is a Javascript reserved word...

Early versions of jQuery allowed find and filter to take a second optional argument that was a function. When that was provided it would do an each with that function using the find/filter elements and not change the chain. So your example above would just use find instead of with and it would work just the way you want.

I don&#039;t recall why that feature was removed; I know it was the subject of some extended discussion on a jQuery list at the time.</description>
		<content:encoded><![CDATA[<p>I like the idea, but &#8220;with&#8221; is a Javascript reserved word&#8230;</p>
<p>Early versions of jQuery allowed find and filter to take a second optional argument that was a function. When that was provided it would do an each with that function using the find/filter elements and not change the chain. So your example above would just use find instead of with and it would work just the way you want.</p>
<p>I don&#8217;t recall why that feature was removed; I know it was the subject of some extended discussion on a jQuery list at the time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2073</link>
		<dc:creator>James</dc:creator>
		<pubDate>Tue, 30 Dec 2008 23:03:40 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2073</guid>
		<description>Great! I&#039;m glad you all like it! :)</description>
		<content:encoded><![CDATA[<p>Great! I&#8217;m glad you all like it! <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ignite</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2063</link>
		<dc:creator>ignite</dc:creator>
		<pubDate>Tue, 30 Dec 2008 19:44:14 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2063</guid>
		<description>Very nice! I really enjoy these tips. I&#039;m still learning jQuery so your explanations and examples have been really helpful. Thanks!</description>
		<content:encoded><![CDATA[<p>Very nice! I really enjoy these tips. I&#8217;m still learning jQuery so your explanations and examples have been really helpful. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ibrahim</title>
		<link>http://james.padolsey.com/javascript/jquery-with-method/comment-page-1/#comment-2062</link>
		<dc:creator>Ibrahim</dc:creator>
		<pubDate>Tue, 30 Dec 2008 19:44:10 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=297#comment-2062</guid>
		<description>Very impressive, thanks James ;)</description>
		<content:encoded><![CDATA[<p>Very impressive, thanks James <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

