<?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) .nextOrFirst() function guarantees a selection</title>
	<atom:link href="http://www.mattvanandel.com/999/jquery-nextorfirst-function-guarantees-a-selection/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattvanandel.com/999/jquery-nextorfirst-function-guarantees-a-selection/</link>
	<description>Web Development for the Developmentally Challenged</description>
	<lastBuildDate>Fri, 25 Feb 2011 20:42:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: Matt</title>
		<link>http://www.mattvanandel.com/999/jquery-nextorfirst-function-guarantees-a-selection/comment-page-1/#comment-7</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 25 Feb 2011 20:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattvanandel.com/?p=999#comment-7</guid>
		<description>That&#039;s definitely a more efficient solution. Thanks for sharing!</description>
		<content:encoded><![CDATA[<p>That&#8217;s definitely a more efficient solution. Thanks for sharing!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: billyzkid</title>
		<link>http://www.mattvanandel.com/999/jquery-nextorfirst-function-guarantees-a-selection/comment-page-1/#comment-6</link>
		<dc:creator>billyzkid</dc:creator>
		<pubDate>Fri, 25 Feb 2011 04:25:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattvanandel.com/?p=999#comment-6</guid>
		<description>Nice idea, but I think these are more concise, faster (less jQuery object creation), and avoids a subtle bug. It looks your children selector will only check the first/last child of the parent before filtering, whereas these functions will always find the correct first/last match:

$.fn.nextOrFirst = function(selector)
{
    var next = this.next(selector);
    return (next.length) ? next : this.prevAll(selector).last();
};

$.fn.prevOrLast = function(selector)
{
    var prev = this.prev(selector);
    return (prev.length) ? prev : this.nextAll(selector).last();
};</description>
		<content:encoded><![CDATA[<p>Nice idea, but I think these are more concise, faster (less jQuery object creation), and avoids a subtle bug. It looks your children selector will only check the first/last child of the parent before filtering, whereas these functions will always find the correct first/last match:</p>
<p>$.fn.nextOrFirst = function(selector)<br />
{<br />
    var next = this.next(selector);<br />
    return (next.length) ? next : this.prevAll(selector).last();<br />
};</p>
<p>$.fn.prevOrLast = function(selector)<br />
{<br />
    var prev = this.prev(selector);<br />
    return (prev.length) ? prev : this.nextAll(selector).last();<br />
};</p>
]]></content:encoded>
	</item>
</channel>
</rss>

