<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UnDeprived &#187; $(selectors)</title>
	<atom:link href="http://www.un-deprived.com/tag/selectors/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.un-deprived.com</link>
	<description>A webdev journal of the Moninator</description>
	<lastBuildDate>Sun, 29 Aug 2010 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>jQuery Journal: each() vs Selectors</title>
		<link>http://www.un-deprived.com/2009/webdev/jquery-journal-each-vs-selectors/</link>
		<comments>http://www.un-deprived.com/2009/webdev/jquery-journal-each-vs-selectors/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 21:25:11 +0000</pubDate>
		<dc:creator>Mon</dc:creator>
				<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[$(selectors)]]></category>
		<category><![CDATA[each()]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.un-deprived.com/?p=117</guid>
		<description><![CDATA[One of the first few things I learned in jQuery, importantly enough that I can’t live without this function.  I like to note that when I first learned jQuery, I was a bit confused of the Selectors and the each() core function. After I got a hang of how to use the Selectors, I slowly [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>One of the first few things I learned in jQuery, importantly enough that I can’t live without this function.  I like to note that when I first learned jQuery, I was a bit confused of the Selectors and the each() core function. After I got a hang of how to use the Selectors, I slowly grasp the usage of each(). A few things to note about the two:</p>
<ul>
<li>$(selectors) selects <em>everything</em> that you feed to it</li>
<li>The each() function is used <em>conjunctionally</em> with $(selectors)</li>
<li>The each() function <em>separates</em> each of the returned item from the $(selectors) individually</li>
</ul>
<p><strong>Why you probably can’t live without each()</strong></p>
<p>Let’s say you want to change all the paragraphs (&lt;p&gt;) into I don’t know… say “No paragraph for you!” to all of them:</p>
<p>From:</p>
<div class="wp_syntax">
<div class="code">
<pre class="html" style="font-family:monospace;">This is a paragraph 1
&nbsp;
Second paragraph
&nbsp;
3rd paragraph</pre>
</div>
</div>
<p>To:</p>
<div class="wp_syntax">
<div class="code">
<pre class="html" style="font-family:monospace;">No paragraph for you!
&nbsp;
No paragraph for you!
&nbsp;
No paragraph for you!</pre>
</div>
</div>
<p>All you have to do is one fell swoop with jQuery:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;">	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;No paragraph for you!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>What if you  want to change the text individually ONLY when the user clicks on each of the paragraph? That’s when each() comes in as hero of the day:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;No paragraph for you!!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p><a href="http://www.un-deprived.com/wp-content/uploads/2009/07/each.html">The above example</a> / <a href="http://www.un-deprived.com/wp-content/uploads/2009/07/image-swaps.html">Image Swap Example using each()</a></p>
<p>That’s just the most basic use of the each() function, if you still don’t see the light with the above examples, let me know.<!-- PHP 5.x --></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.un-deprived.com/2009/webdev/jquery-journal-each-vs-selectors/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
	</channel>
</rss>
