<?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: :first Selector</title>
	<atom:link href="http://api.jquery.com/first-selector/feed/" rel="self" type="application/rss+xml" />
	<link>http://api.jquery.com/first-selector/</link>
	<description>jQuery API Reference</description>
	<lastBuildDate>Fri, 19 Aug 2011 09:06:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Chris</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-7895</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sat, 06 Nov 2010 01:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-7895</guid>
		<description>I did a test using firebugs console.time, and doing a $(&#039;.blah&#039;) vs. $(&#039;.blah:first&#039;), with no :first the test came back 0 ms, and with :first it took 4 ms, then putting both of those in a loop and ran each 1 thousand times, no first was on the order of a hundred ms, while first was on the order of 1000 ms. So doing :first does not actually stop the query from checking the rest of the dom, so you are better off not doing :first, at least until browsers and js are smart enough to stop checking the dom.</description>
		<content:encoded><![CDATA[<p>I did a test using firebugs console.time, and doing a $(&#39;.blah&#39;) vs. $(&#39;.blah:first&#39;), with no :first the test came back 0 ms, and with :first it took 4 ms, then putting both of those in a loop and ran each 1 thousand times, no first was on the order of a hundred ms, while first was on the order of 1000 ms. So doing :first does not actually stop the query from checking the rest of the dom, so you are better off not doing :first, at least until browsers and js are smart enough to stop checking the dom.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-6825</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 05 Nov 2010 17:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-6825</guid>
		<description>I did a test using firebugs console.time, and doing a $(&#039;.blah&#039;) vs. $(&#039;.blah:first&#039;), with no :first the test came back 0 ms, and with :first it took 4 ms, then putting both of those in a loop and ran each 1 thousand times, no first was on the order of a hundred ms, while first was on the order of 1000 ms. So doing :first does not actually stop the query from checking the rest of the dom, so you are better off not doing :first, at least until browsers and js are smart enough to stop checking the dom.</description>
		<content:encoded><![CDATA[<p>I did a test using firebugs console.time, and doing a $(&#39;.blah&#39;) vs. $(&#39;.blah:first&#39;), with no :first the test came back 0 ms, and with :first it took 4 ms, then putting both of those in a loop and ran each 1 thousand times, no first was on the order of a hundred ms, while first was on the order of 1000 ms. So doing :first does not actually stop the query from checking the rest of the dom, so you are better off not doing :first, at least until browsers and js are smart enough to stop checking the dom.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Proctor</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5775</link>
		<dc:creator>Roger Proctor</dc:creator>
		<pubDate>Wed, 15 Sep 2010 06:13:45 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5775</guid>
		<description>simple question more to with firebug console debugger why does :first get identified as unknown pseudo-class</description>
		<content:encoded><![CDATA[<p>simple question more to with firebug console debugger why does :first get identified as unknown pseudo-class</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benjamin H Kohl</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5594</link>
		<dc:creator>Benjamin H Kohl</dc:creator>
		<pubDate>Thu, 26 Aug 2010 11:27:32 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5594</guid>
		<description>Why are people so concerned about milliseconds?  If you have to use any tools to measure the difference in performance of these various selectors, then the difference is negligible.  When you buy a box of cereal, do you take it home and check to make sure the box contains the exact number of ounces that is displayed on the box?  Unless you are obsessive, you probably don&#039;t.  I have ever executed some JQuery and said to myself, &quot;That is 14ms of my life I wish I had back.&quot;</description>
		<content:encoded><![CDATA[<p>Why are people so concerned about milliseconds?  If you have to use any tools to measure the difference in performance of these various selectors, then the difference is negligible.  When you buy a box of cereal, do you take it home and check to make sure the box contains the exact number of ounces that is displayed on the box?  Unless you are obsessive, you probably don&#39;t.  I have ever executed some JQuery and said to myself, &#8220;That is 14ms of my life I wish I had back.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MrBester</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5596</link>
		<dc:creator>MrBester</dc:creator>
		<pubDate>Thu, 24 Jun 2010 06:09:11 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5596</guid>
		<description>FWIW:&lt;br&gt;console.time(&#039;loop&#039;); for(var i=0; i&lt;1000; i++){$(&#039;div&#039;).eq(0);} console.timeEnd(&#039;loop&#039;);&lt;br&gt;is only 7.5% slower than not specifying the index, but including &#039;:first&#039; nearly doubles the time taken. At least it does on a simple example page I&#039;m using to test. If every ns counts then speciying the index is the way to go, unless someone feels like forking Sizzle to short-circuit the &#039;:first&#039; selector. No, didn&#039;t think so...</description>
		<content:encoded><![CDATA[<p>FWIW:<br />console.time(&#39;loop&#39;); for(var i=0; i&lt;1000; i++){$(&#39;div&#39;).eq(0);} console.timeEnd(&#39;loop&#39;);<br />is only 7.5% slower than not specifying the index, but including &#39;:first&#39; nearly doubles the time taken. At least it does on a simple example page I&#39;m using to test. If every ns counts then speciying the index is the way to go, unless someone feels like forking Sizzle to short-circuit the &#39;:first&#39; selector. No, didn&#39;t think so&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: milesslow</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5597</link>
		<dc:creator>milesslow</dc:creator>
		<pubDate>Sun, 06 Jun 2010 01:50:17 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5597</guid>
		<description>Wow, you&#039;re right.  I guess I was forgetting that computers don&#039;t understand the semantics of the &#039;:first&#039; selector.  They treat it like any other position selector, which I think are processed at the very end (consider the &#039;:last&#039; selector, which can only be processed after all matching elements are found).  That&#039;s what I get from glancing at the sizzlejs source.  Honestly, it doesn&#039;t matter if it takes twice as long (three times on my page), because it takes &lt; 1ms for either selector, and if you ever use a position selector 1000 times in a row, you should be using a better data structure than an html document.</description>
		<content:encoded><![CDATA[<p>Wow, you&#39;re right.  I guess I was forgetting that computers don&#39;t understand the semantics of the &#39;:first&#39; selector.  They treat it like any other position selector, which I think are processed at the very end (consider the &#39;:last&#39; selector, which can only be processed after all matching elements are found).  That&#39;s what I get from glancing at the sizzlejs source.  Honestly, it doesn&#39;t matter if it takes twice as long (three times on my page), because it takes &lt; 1ms for either selector, and if you ever use a position selector 1000 times in a row, you should be using a better data structure than an html document.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5595</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Thu, 03 Jun 2010 14:52:00 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5595</guid>
		<description>Using first in theory should be much faster but in practice it can be quite a bit slower. Try this:&lt;br&gt;console.time(&#039;loop&#039;); for(var i=0; i&lt;1000; i++){$(&#039;div&#039;);} console.timeEnd(&#039;loop&#039;);&lt;br&gt;vs this:&lt;br&gt;console.time(&#039;loop&#039;); for(var i=0; i&lt;1000; i++){$(&#039;div:first&#039;);} console.timeEnd(&#039;loop&#039;);&lt;br&gt;&lt;br&gt;On one page I am working on the second takes twice as long. Weird.</description>
		<content:encoded><![CDATA[<p>Using first in theory should be much faster but in practice it can be quite a bit slower. Try this:<br />console.time(&#39;loop&#39;); for(var i=0; i&lt;1000; i++){$(&#39;div&#39;);} console.timeEnd(&#39;loop&#39;);<br />vs this:<br />console.time(&#39;loop&#39;); for(var i=0; i&lt;1000; i++){$(&#39;div:first&#39;);} console.timeEnd(&#39;loop&#39;);</p>
<p>On one page I am working on the second takes twice as long. Weird.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: milesslow</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5604</link>
		<dc:creator>milesslow</dc:creator>
		<pubDate>Fri, 09 Apr 2010 02:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5604</guid>
		<description>If performance is your only concern, and you know the selector is only going to match one element, then YES, use the &#039;:first&#039; selector.  The truth is, $(&#039;tr:first&#039;) is either going to be a lot faster than $(&#039;tr&#039;), or negligibly slower.  If it bothers you not knowing for sure, then please take a stab at reading through Sizzle, and let us know what you find out.</description>
		<content:encoded><![CDATA[<p>If performance is your only concern, and you know the selector is only going to match one element, then YES, use the &#39;:first&#39; selector.  The truth is, $(&#39;tr:first&#39;) is either going to be a lot faster than $(&#39;tr&#39;), or negligibly slower.  If it bothers you not knowing for sure, then please take a stab at reading through Sizzle, and let us know what you find out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hc</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5603</link>
		<dc:creator>hc</dc:creator>
		<pubDate>Thu, 08 Apr 2010 16:03:14 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5603</guid>
		<description>Wow, I shouldn&#039;t have given an example, as people seem to focus on that instead of the actual question about performance.  The table example was for illustrative purposes only.  Obviously it&#039;s not real.  What&#039;s the point of a table with only one row?  &lt;br&gt;&lt;br&gt;My question is, when you have a selector (any selector), that you know will only return one element, is the jQuery processing faster if you explicitly include &quot;:first&quot;.  My inclination is that &quot;:first&quot; would be faster, because as it travels the DOM looking for matches, it stops as soon as it finds one, whereas a selector WITHOUT &quot;:first&quot; would have to continue looking for matches even if ultimately there is only one match.  But that&#039;s just my hunch, and it&#039;d be nice if someone could definitively say which is true, preferably with performance statistics.  I guess I&#039;ll have to do some measurements myself.</description>
		<content:encoded><![CDATA[<p>Wow, I shouldn&#39;t have given an example, as people seem to focus on that instead of the actual question about performance.  The table example was for illustrative purposes only.  Obviously it&#39;s not real.  What&#39;s the point of a table with only one row?  </p>
<p>My question is, when you have a selector (any selector), that you know will only return one element, is the jQuery processing faster if you explicitly include &#8220;:first&#8221;.  My inclination is that &#8220;:first&#8221; would be faster, because as it travels the DOM looking for matches, it stops as soon as it finds one, whereas a selector WITHOUT &#8220;:first&#8221; would have to continue looking for matches even if ultimately there is only one match.  But that&#39;s just my hunch, and it&#39;d be nice if someone could definitively say which is true, preferably with performance statistics.  I guess I&#39;ll have to do some measurements myself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: R Bemrose</title>
		<link>http://api.jquery.com/first-selector/comment-page-1/#comment-5602</link>
		<dc:creator>R Bemrose</dc:creator>
		<pubDate>Thu, 08 Apr 2010 15:04:33 +0000</pubDate>
		<guid isPermaLink="false">http://api.jquery.com/?p=546#comment-5602</guid>
		<description>I would still stick to the version with the :first selector, as it somewhat future proofs things.&lt;br&gt;&lt;br&gt;In fact, to REALLY future proof it, perhaps it should be:&lt;br&gt;$(&#039;table &gt; tbody &gt; tr:first&#039;)&lt;br&gt;This is assuming any table headers ( tags) would be in a</description>
		<content:encoded><![CDATA[<p>I would still stick to the version with the :first selector, as it somewhat future proofs things.</p>
<p>In fact, to REALLY future proof it, perhaps it should be:<br />$(&#39;table &gt; tbody &gt; tr:first&#39;)<br />This is assuming any table headers ( tags) would be in a</p>
]]></content:encoded>
	</item>
</channel>
</rss>

