<?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>eligeske &#187; JQuery</title>
	<atom:link href="http://eligeske.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://eligeske.com</link>
	<description>My day to day journey through the world wide web.</description>
	<lastBuildDate>Tue, 15 Jun 2010 20:39:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript Dedup an Array</title>
		<link>http://eligeske.com/jquery/javascript-dedup-and-array-array_unique/</link>
		<comments>http://eligeske.com/jquery/javascript-dedup-and-array-array_unique/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 20:35:38 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=226</guid>
		<description><![CDATA[<img src="http://eligeske.com/wp-content/uploads/2009/11/category-jquery.jpg" alt="jQuery" title="Javascript Deduping" width="150" height="150" class="alignnone size-full wp-image-73" /> Short function to remove the duplicate entries from a Javascript array. Comparable to php's unique_array.]]></description>
			<content:encoded><![CDATA[<p>Here is a simple javascript function do remove the duplicate values in an array.  It worked very well for what I needed it for, although it may not be full proof for your application.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">function dedupArray(array)
{
array.sort();
var cnt = array.length &amp;#8211; 1;
var i=0;
var keepers = new Array();
while(i &lt;= cnt){
if(array[i] != array[i + 1]){
keepers.push(array[i]);
i++;
}else{
array.shift();
}
cnt = array.length &amp;#8211; 1;
}
return keepers;
}</pre></div></p>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/javascript-dedup-and-array-array_unique/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>While Loop with JQuery</title>
		<link>http://eligeske.com/jquery/while-loop-with-jquery/</link>
		<comments>http://eligeske.com/jquery/while-loop-with-jquery/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 18:46:50 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=217</guid>
		<description><![CDATA[<img src="http://eligeske.com/wp-content/uploads/2009/11/category-jquery.jpg" alt="jQuery" title="JQuery Looping" width="150" height="150" class="alignnone size-full wp-image-73" /> As the days pass I am forced to learn more and more about JQuery. Of course loving every minute of it. Today is about looping through some elements with JQuery.]]></description>
			<content:encoded><![CDATA[<p>So you want to loop through some elements using JQuery. Me too!  We have something in common, maybe we should go have a beer together.  Bud light anyone?  just kidding. (about the bud light, ik.)</p>
<p>There is some important things when trying to loop through elements with JQuery.</p>
<ol>
<li>Need to get an array of elements OR use .each function  (but there can be some issues there)</li>
<li>Loop through those elements</li>
</ol>
<p>First: Assigning elements to an array.</p>
<p>I want everyone to know right now that I am by far an expert on this subject, but&#8230;&#8230; but&#8230;..  I do think this may help someone out.  If you have some good feedback or improvements please comment below!  The more good info the marry&#8217;er!!!!! &lt;&#8211; is that a word? anyways.</p>
<p>ASSIGN ELEMENTS TO AN ARRAY or grab OBJECTs:</p>
<p>examples:</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">var divs = $('divs');</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">var rows = $('.container .row'); // assigns all class with rows</div></li></ol></pre></div></p>
<p>Once you have that assigned you can get the .length value for looping through. This is different than using the .get() which uses the dom and not JQuery. So for this writeup I will be using the JQuery .eq() function which allowed me to grab out of the array from a JQuery object.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">$cnt = $row.length  // returns count obviously</div></li></ol></pre></div></p>
<p>Now that we have a count of how many are in the array we can do a while loop. (using .eq) and not the .get() which would look like this $row[1]. Instead what we will do will look like this $row.eq(1);. What I used this for was to determine the height of my left column and hide rows that extended the height of the main column past the height of the left. But this is only a portion of that. Here is how i looped through and hid some rows.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">$i = $cnt -1;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">while($i &gt; 0){</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">rows.eq($i).slideUp(); // slides up all the rows</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">}</div></li></ol></pre></div></p>
<p>SO HEY YOU! WHY NOT JUST USE THE .each() FUNCTION BUILT INTO JQuery!!!!!</p>
<p>Ok. I&#8217;ll tell you why, or at least a partial why.  Here is the partial why.</p>
<p>When using the .each function it appeared that it did not do a full iteration and complete all the code sequentially.  For some reason, here is the partial I can&#8217;t cover yet, the .each function iterated each part in the enclosed function at the same time not allow me to determine things in between each loop. Which forced me to learn how to traverse the JQuery object.  Which is good because using this way was WAY less code than I was about to write out of my shear laziness.</p>
<p>I hope this has helped someone else out there wanting to loop through some elements. Oh and here is the code I used to hide some rows that were making the main page container not match the height to the left column. In case you were  curious.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">function squishBox(){</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">var rows = $('.products_cont .row');</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">$cnt = rows.length;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">$i = $cnt &amp;#8211; 1;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">while($i &gt; 0){</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">$left_height = $('#LEFTPANE').height();</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">$main_height = $('#CONTENTPANE').height();</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">if($left_height &lt; $main_height &amp;#8211; 100){</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">rows.eq($i).slideUp();</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">$i&amp;#8211;;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">}</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em arial; margin:0; padding:0; background:none; vertical-align:top;">}</div></li></ol></pre></div></p>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/while-loop-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Combining $(this) with selector</title>
		<link>http://eligeske.com/jquery/combining-this-with-element-selector/</link>
		<comments>http://eligeske.com/jquery/combining-this-with-element-selector/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 15:41:23 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=181</guid>
		<description><![CDATA[<img src="http://eligeske.com/wp-content/uploads/2009/11/category-jquery.jpg" alt="jQuery category" title="jquery $this with other selectors" width="150" height="150" class="alignnone size-full wp-image-73" />Stacking $(this) and other element selectors can be frustrating to some at times. This is a quick one to assist with it.]]></description>
			<content:encoded><![CDATA[<p>Ok, I know that there are many times where you may be using a click function of an element but you need to use specifically that element you clicked siblings or children.  Being able to stack the $(this) selector with other ones can be a little difficult or puzzling at times.  Check below on a couple different ways of sticking them together.</p>
<p>Notice in the code that a comma &#8220;,&#8221; is used and not the concatenation plus &#8220;+&#8221;.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">// find out if a selected element's is visible.
$visible = $(this,&quot;:visible&quot;).length; // returns true of false
// find out if a selected element's immediate sibling div is visible.
$visible = $(this).next('div:visible').length; // returns true of false
// hide the selected previous siblings element, &lt;span&gt;hide me&lt;/span&gt;&lt;element&gt;this&lt;/element&gt;
$('+ span', this).hide();
// hide the selected element's child with the class name .class
$(this,&quot;.class&quot;).hide(); // returns true of false</pre></div></p>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/combining-this-with-element-selector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery checkbox.val always on?</title>
		<link>http://eligeske.com/jquery/jquery-checkbox-val-always-on/</link>
		<comments>http://eligeske.com/jquery/jquery-checkbox-val-always-on/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 15:34:35 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=137</guid>
		<description><![CDATA[<img src="http://eligeske.com/wp-content/uploads/2009/11/category-jquery.jpg" alt="jQuery category" title="jquery checkbox.val always on?" width="150" height="150" class="alignnone size-full wp-image-73" /> Attempting to check the value of a form checkbox field? I was and it was always returning on. Find out why.]]></description>
			<content:encoded><![CDATA[<p>When using JQuery selectors and trying to get the value of a checkbox, it seems that it will always return the result &#8220;on&#8221;.  That is because you need to check to see if it is &#8220;:checked&#8221; instead of trying to grab the value of it.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">if($(&quot;input[name='YourCheckboxName']&quot;).is(&quot;:checked&quot;)){
alert('on');
}else{
alert('off');
}</pre></div></p>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/jquery-checkbox-val-always-on/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JQuery &#8211; Run script if!</title>
		<link>http://eligeske.com/jquery/jquery-run-script-if/</link>
		<comments>http://eligeske.com/jquery/jquery-run-script-if/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 16:39:57 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=120</guid>
		<description><![CDATA[<img src="http://eligeske.com/wp-content/uploads/2009/11/category-jquery.jpg" alt="jQuery" title="jQuery Run Script if" width="150" height="150" class="alignnone size-full wp-image-73" /> When running a site with a boat load of javascript, you may want to run a script only if a certain something is on the page. Run my enclosed script only if......]]></description>
			<content:encoded><![CDATA[<p>When running a site with a boat load of javascript, you may want to run a script only if a certain something is on the page.  Not only could this save on initial loading time, but more importantly if you have an element of one thing on one page and the same named element for something else on another. You don&#8217;t want your JQuery to do an action to that if it isn&#8217;t intended.</p>
<p>So.  Run my enclosed script if!  I read somewhere a while back on a nice way of determining if an element exists. Really simple and I definitely cannot take credit for this.</p>
<p>Let&#8217;s say you have a div on your index page you have some classes you want to change on page load. But on another page you have some more of those classes.</p>
<p>You could either have an entirely new javascript page for that page || you could do the following.</p>
<p>Create something with a unique id that you don&#8217;t plan on using elsewhere on your site, so maybe the page name.   &lt;body id=&#8221;myPageName&#8221;&gt;</p>
<p>Then all you need to do for JQuery is the following:</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">if ($('#myPageName').length &gt; 0){
//everything you want to run inside here.   
}</pre></div></p>
<p>Got any other ideas that would work besides this? Please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/jquery-run-script-if/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>JQuery &#8211; Star Comment Rating</title>
		<link>http://eligeske.com/jquery/jquery-star-comment-rating/</link>
		<comments>http://eligeske.com/jquery/jquery-star-comment-rating/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 21:07:51 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=54</guid>
		<description><![CDATA[<img src="http://eligeske.com/wp-content/uploads/2009/09/jQuery-Star-Rating.jpg" alt="jQuery-Star-Rating" title="jQuery-Star-Rating" width="150" height="150" class="alignnone size-full wp-image-73" /> JQuery and CSS, what a lovely combination! If you've ever needed a quick rating bar that is smooth, pretty, and fast, here it is. Here I used CSS Sprite images and some quick and simple JQuery for show, hide, and fade for some nice effects. Hey! The source code is even available.]]></description>
			<content:encoded><![CDATA[<p>Here is a nice little rating effect. This does not include the PHP, it is only the JavaScript, HTML, CSS, and Images. If you like this, I do have the PHP script that I created, but will not support, and I threw together quite quickly.  But, what the heck, back to this post now.</p>
<p>Look below and you can see what will be created by the time we are done with this project.<br />
<iframe src="http://eligeske.info/tutorials/jquery/star-rating/star_rating.html" frameborder="0" scrolling="no" height="55" width="200"></iframe><br />
<a href="#full_source"> Skip to full source code</a> || <a href="http://eligeske.info/tutorials/jquery/star-rating/star-rating.zip">Download Source in .zip</a></p>
<p>What we start with is one HTML file, JQUERY library, star_rating.js (contains all the effects), and the image folder with some images.</p>
<p><strong>First let’s take a look at the file structure.</strong></p>
<p><img class="alignnone size-full wp-image-65" title="star-rating file structure" src="http://eligeske.com/wp-content/uploads/2009/09/file-structure.jpg" alt="star-rating file structure" width="305" height="232" /></p>
<p>Right now I contain all the CSS in the html file, out of shear laziness, and so you don’t have an extra file with a small amount of CSS in it.</p>
<p>So let’s talk about the html.</p>
<p>Everything except the hidden form field that contains the final rating selected is contained within the rating_cont div.</p>
<p>Inside the main rating_cont div is three more divs.</p>
<ol>
<li>rating_btns div.</li>
<li>rating_on div.</li>
<li>rated div.</li>
</ol>
<div class="wp-synhighlighter-inner"><pre class="html4strict" style="font-family:arial;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_cont&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_btns&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_on&quot;</span> &gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rated&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_output&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_output&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;not rated&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></p>
<p>Now that we have the main divs setup, let’s add some of the style so we can see what we are working with.</p>
<p>We will add the following CSS to the rating_cont, our main div.</p>
<div class="wp-synhighlighter-inner"><pre class="css" style="font-family:arial;"><span style="color: #cc00cc;">#rating_cont</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#1E1D1C</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/rating_background.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#F9BA0D</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">140px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">23px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></p>
<p>This puts the background image of the stars ‘off’ and creates our height, width, border, and background for our main container.</p>
<p>Next, let’s create the CSS and html for the rating_btns div.</p>
<p>The rating_btns div will have an unordered list with the actual ratings in it.</p>
<p>Look below.</p>
<div class="wp-synhighlighter-inner"><pre class="html4strict" style="font-family:arial;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>0.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>1.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>1.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>2.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>2.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>3.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>3.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>4.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>4.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>5.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span></pre></div></p>
<p>If you’re doing the code step by step, I’m sure you noticed that this looks pretty ugly right now.  Let’s add the CSS to the rating_btns div and the ul we have.</p>
<p>The rating_btns div needs to be above the rating_on div that we will create next, so we will give it a relative positioning and a z-index of 100. We also add the height and width to define the container of our &lt;li&gt; links.</p>
<p>Inside the rating_btns div is our &lt;ul&gt; and it’s &lt;li&gt;. We do not want our &lt;ul&gt; or our &lt;li&gt; to have any margin or padding.  The &lt;li&gt; needs to be 14px wide. Guess why.  14 x 100 = 140! Yup, you got it. That is the width of our container, amazing, I know. We are going to float them left, give them a block display so they don’t go over each other, and last but not least, change the font display. We will change the font to 1px, and the same color as the background. I’m sure you’re asking; why not just have them empty and not have any text in there at all? Well, we will use this text to tell our JQuery script what you hovered over.</p>
<p>Here is the CSS for this.</p>
<div class="wp-synhighlighter-inner"><pre class="css" style="font-family:arial;"><span style="color: #cc00cc;">#rating_btns</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">140px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">21px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#rating_btns</span> ul<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#rating_btns</span> li  <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#rating_btns</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">14px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">21px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#1E1D1C</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></p>
<p>Next, look at our rating_on div. Just as it says, it is our div that contains our stars that are “ON”.  We use a quite unique way of doing this. We give it a background image of the “on” stars, but change it’s width based upon what we hover over. That’s the reason we had to give the rating_btns a relative positioning with a z-index, and this div we will also give a relative positioning, but a z-index of 50. We will also set the width to 0px initially, so it doesn’t show before we hover over it.</p>
<p>Here is the HTML for this:</p>
<div class="wp-synhighlighter-inner"><pre class="html4strict" style="font-family:arial;">#rating_on { background: url(images/rating_onbackground.jpg) top left no-repeat; width: 0px; height: 21px; position: relative; z-index: 50; top: -21px; }
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_on&quot;</span> &gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></pre></div></p>
<p>On to our last div, our rating div, this contains three smaller divs that act as cells, one containing the selected rating, another containing the image of the stars, and the last one containing our edit link.</p>
<p>I still haven&#8217;t gotten to the JQuery yet, so I will just show you the CSS, and HTML for this.</p>
<div class="wp-synhighlighter-inner"><pre class="html4strict" style="font-family:arial;">#rated { display: none; width: 138px; padding: 3px 0px 3px 2px; height: 23px; background-color: #1E1D1C; height: 17px;font-size: 11px;color: #FFC910;}
#rated div { display: block; float: left; }
#rating { font-size: 11px; font-family: Arial, Helvetica, sans-serif; color: #FFC910; padding-left: 3px; width: 22px; }
#small_stars { height: 11px; width: 69px; background-image: url(images/stars_small_sprite.jpg); background-position: 0px -11px; font-size:1px; line-height: 11px; margin-top:3px; }
#rate_edit { line-height: 17px; font-size: 11px; font-family: Arial, Helvetica, sans-serif; color: #FFF; padding-left: 9px; cursor: pointer; }
#rate_edit:hover { text-decoration: underline; }
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rated&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;height: 17px; line-height: 17px;&quot;</span>&gt;</span>not rated<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span> <span style="color: #ddbb00;">&amp;#8211;</span> <span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;small_stars&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rate_edit&quot;</span>&gt;</span>edit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></pre></div></p>
<p>Since this will be used to send a rating from a form, we will add a hidden form field to be sent. This will be updated from JQuery.</p>
<div class="wp-synhighlighter-inner"><pre class="html4strict" style="font-family:arial;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_output&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_output&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;not rated&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></p>
<p>Ok, on to the fun stuff, the JQuery.</p>
<p>This will have a total of six functions, NOT including the document.ready function.</p>
<ol>
<li>rateWidth      function</li>
<li>starSprite      function</li>
<li>hover      function *JQuery</li>
<li>mouseout      function *JQuery</li>
<li>click      function *JQuery</li>
<li>edit      function *JQuery</li>
</ol>
<p>With JQuery we need to surround it’s functions with $(document).ready(function()).</p>
<p>In saying that, keep that in mind when you look at the source code. If you don&#8217;t know what I am talking about, check out the full source code at the end of this post, or the downloadable source code.</p>
<p><strong>1. rateWidth function<br />
</strong>This function accepts the rating variable from our JQuery functions, converts it to an Integer, uses a switch statement to determine the width value, then returns the width to make our rating_on div show the stars. (shows the stars).</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">function rateWidth($rating){
$rating = parseFloat($rating);
switch ($rating){
case 0.5: $width = &quot;14px&quot;; break;
case 1.0: $width = &quot;28px&quot;; break;
case 1.5: $width = &quot;42px&quot;; break;
case 2.0: $width = &quot;56px&quot;; break;
case 2.5: $width = &quot;70px&quot;; break;
case 3.0: $width = &quot;84px&quot;; break;
case 3.5: $width = &quot;98px&quot;; break;
case 4.0: $width = &quot;112px&quot;; break;
case 4.5: $width = &quot;126px&quot;; break;
case 5.0: $width = &quot;140px&quot;; break;
default:  $width =  &quot;84px&quot;;
}
return $width;
}</pre></div></p>
<p><strong>2. starSprite function<br />
</strong>I used two different methods for creating the stars. One uses less HTML, and one uses more. For the small stars that show up when you make a rating, I wanted to use less HTML and used the sprite method to show the rating.  But it does the same thing as the rateWidth but determines the background positioning based on the rating provided.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">function starSprite($rating){
$rating = parseFloat($rating);
switch ($rating){
case 0.5: $pos = &quot;-11px&quot;; break;
case 1.0: $pos = &quot;-22px&quot;; break;
case 1.5: $pos = &quot;-33px&quot;; break;
case 2.0: $pos = &quot;-44px&quot;; break;
case 2.5: $pos = &quot;-55px&quot;; break;
case 3.0: $pos = &quot;-66px&quot;; break;
case 3.5: $pos = &quot;-77px&quot;; break;
case 4.0: $pos = &quot;-88px&quot;; break;
case 4.5: $pos = &quot;-99px&quot;; break;
case 5.0: $pos = &quot;-110px&quot;; break;
default:  $pos =  &quot;-77px&quot;;
}
return $pos;
}</pre></div></p>
<p><strong>3. hover function *JQuery<br />
</strong>The hover function will detect the cursor hovering over our &lt;li&gt;’s and the value of it and then send the value to the rateWidth function to get our width. It then assigns the width to the #rating_on div.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">$('#rating_btns li').hover(function(){
$rating = $(this).text();
$('#rating_on').css('width', rateWidth($rating));
});</pre></div></p>
<p><strong>4. mouseout function<br />
</strong>The mouseout function does just that, tells what stars should be showing on mouseout. But we do not want the stars to be reset every time we go off the stars, especially if we already selected a rating.  So we grab the value of our #rating div and if it is “not rated” we set our width to 0px but if it doesn’t equal “not rated” we set the width of it’s set value.  This way if you have selected a rating it defaults back to it when you mouseout.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">$('#rating_btns li').mouseout(function(){
$rating = $('#rating').text();
if($rating == &quot;not rated&quot;){
$('#rating_on').css('width', &quot;0px&quot;);
}
else{
$('#rating_on').css('width', rateWidth($rating));
}
});</pre></div></p>
<p><strong>5.  click function</strong><br />
This function has a little bit more going on than the other ones. When you click the &lt;li&gt; it first grabs the value of the clicked &lt;li&gt; assigns it to the #rating div, uses starSprite function to assign the background position for the #small_stars div, then hides the #rating_btns div, and the #rating_on div. Once hidden, it nicely fades in the #rated div.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">$('#rating_btns li').click(function(){
$rating = $(this).text();
$('#rating').text($rating);
$('#rating_output').val($rating);
$pos = starSprite($rating);
$('#small_stars').css('background-position', &quot;0px &quot; + $pos );
$('#rating_btns').hide();
$('#rating_on').hide();
$('#rated').fadeIn();
});</pre></div></p>
<p><strong>6. edit function</strong><br />
This function just hides the #rated div and fades in the two divs we just hid. The #rating_div and the #rating_btns div.</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">$('#rate_edit').click(function(){
$('#rated').hide();
$('#rating_btns').fadeIn();
$('#rating_on').fadeIn();
});</pre></div></p>
<p>Bam&#8230; we’re done.</p>
<p><a name="full_source">FULL SOURCE CODE</a></p>
<p>Here is the completed code for your viewing pleasure.</p>
<p><strong>HTML (star_rating.html) -</strong></p>
<div class="wp-synhighlighter-inner"><pre class="html4strict" style="font-family:arial;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>JQuery-Star Comment Rating<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery/jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/star_rating.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
#rating_cont { background: #1E1D1C url(images/rating_background.jpg) top left no-repeat; border: 1px solid #F9BA0D; width: 140px; height: 23px; text-align: left; margin-left: 6px;}
#rating_on { background: url(images/rating_onbackground.jpg) top left no-repeat; width: 0px; height: 21px; position: relative; z-index: 50; top: -21px; }
#rated { display: none; width: 138px; padding: 3px 0px 3px 2px; height: 23px; background-color: #1E1D1C; height: 17px;font-size: 11px;color: #FFC910;}
#rated div { display: block; float: left; }
#rating { font-size: 11px; font-family: Arial, Helvetica, sans-serif; color: #FFC910; padding-left: 3px; width: 22px; }
#small_stars { height: 11px; width: 69px; background-image: url(images/stars_small_sprite.jpg); background-position: 0px -11px; font-size:1px; line-height: 11px; margin-top:3px; }
#rate_edit { line-height: 17px; font-size: 11px; font-family: Arial, Helvetica, sans-serif; color: #FFF; padding-left: 9px; cursor: pointer; }
#rate_edit:hover { text-decoration: underline; }
#rating_btns { position: relative; z-index: 100; width: 140px; height: 21px;}
#rating_btns ul, #rating_btns li  { padding: 0; margin: 0; }
#rating_btns li { float: left; width: 14px; height: 21px; display: block; font-size: 1px; cursor: pointer; color: #1E1D1C;
}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_cont&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_btns&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>0.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>1.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>1.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>2.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>2.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>3.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>3.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>4.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>4.5<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>5.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_on&quot;</span> &gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rated&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;height: 17px; line-height: 17px;&quot;</span>&gt;</span>not rated<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span> <span style="color: #ddbb00;">&amp;#8211;</span> <span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;small_stars&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rate_edit&quot;</span>&gt;</span>edit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_output&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rating_output&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></pre></div></p>
<p><strong>JQuery/JavaScript (star_rating.js) -<br />
</strong></p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">/*
* Written by eligeske
* downloaded from eligeske.com
* have fun. nerd.
*/
$(document).ready(function(){
// hover
$('#rating_btns li').hover(function(){
$rating = $(this).text();
$('#rating_on').css('width', rateWidth($rating));
});
// mouseout
$('#rating_btns li').mouseout(function(){
$rating = $('#rating').text();
if($rating == &quot;not rated&quot;){
$('#rating_on').css('width', &quot;0px&quot;);
}
else{
$('#rating_on').css('width', rateWidth($rating));
}
});
//click
$('#rating_btns li').click(function(){
$rating = $(this).text();
$('#rating').text($rating);
$('#rating_output').val($rating);
$pos = starSprite($rating);
$('#small_stars').css('background-position', &quot;0px &quot; + $pos );
$('#rating_btns').hide();
$('#rating_on').hide();
$('#rated').fadeIn();
});
//edit
$('#rate_edit').click(function(){
$('#rated').hide();
$('#rating_btns').fadeIn();
$('#rating_on').fadeIn();
});
function rateWidth($rating){
$rating = parseFloat($rating);
switch ($rating){
case 0.5: $width = &quot;14px&quot;; break;
case 1.0: $width = &quot;28px&quot;; break;
case 1.5: $width = &quot;42px&quot;; break;
case 2.0: $width = &quot;56px&quot;; break;
case 2.5: $width = &quot;70px&quot;; break;
case 3.0: $width = &quot;84px&quot;; break;
case 3.5: $width = &quot;98px&quot;; break;
case 4.0: $width = &quot;112px&quot;; break;
case 4.5: $width = &quot;126px&quot;; break;
case 5.0: $width = &quot;140px&quot;; break;
default:  $width =  &quot;84px&quot;;
}
return $width;
}
function starSprite($rating){
$rating = parseFloat($rating);
switch ($rating){
case 0.5: $pos = &quot;-11px&quot;; break;
case 1.0: $pos = &quot;-22px&quot;; break;
case 1.5: $pos = &quot;-33px&quot;; break;
case 2.0: $pos = &quot;-44px&quot;; break;
case 2.5: $pos = &quot;-55px&quot;; break;
case 3.0: $pos = &quot;-66px&quot;; break;
case 3.5: $pos = &quot;-77px&quot;; break;
case 4.0: $pos = &quot;-88px&quot;; break;
case 4.5: $pos = &quot;-99px&quot;; break;
case 5.0: $pos = &quot;-110px&quot;; break;
default:  $pos =  &quot;-77px&quot;;
}
return $pos;
}
});</pre></div></p>
<p>I hope it works for you all. If you have any questions feel free to leave a comment.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 3824px; width: 1px; height: 1px;"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Wingdings; 	panose-1:5 0 0 0 0 0 0 0 0 0; 	mso-font-charset:2; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:0 268435456 0 0 -2147483648 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}  /* List Definitions */  @list l0 	{mso-list-id:1064138985; 	mso-list-type:hybrid; 	mso-list-template-ids:-1582814268 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 	{mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in;} ol 	{margin-bottom:0in;} ul 	{margin-bottom:0in;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal">This will have a total of six functions, NOT including the document.ready function.</p>
<p class="MsoNormal">
<ol style="margin-top: 0in;" type="1">
<li class="MsoNormal">rateWidth      function</li>
<li class="MsoNormal">starSprite      function</li>
<li class="MsoNormal">hover      function *JQuery</li>
<li class="MsoNormal">mouseout      function *JQuery</li>
<li class="MsoNormal">click      function *JQuery</li>
<li class="MsoNormal">edit      function *JQuery</li>
</ol>
<p class="MsoNormal">
<p class="MsoNormal">With JQuery we need to surround it’s functions with $(document).ready(function()).</p>
<p class="MsoNormal">
<p class="MsoNormal">In saying that, keep that in mind when you look at the source code.</p>
<p class="MsoNormal">
<p class="MsoNormal">1. rateWidth function</p>
<p class="MsoNormal">This function accepts the rating variable from our JQuery functions, converts it to an Integer, uses a switch statement to determine the width value, then returns the width to make our rating_on div show the stars. (shows the stars).</p>
<p class="MsoNormal">
<p class="MsoNormal"><span style="font-family: Wingdings;"><span>ß</span></span><span> </span>jscript rateWidth <span style="font-family: Wingdings;"><span>à</span></span></p>
<p class="MsoNormal">
<p class="MsoNormal">2. starSprite function</p>
<p class="MsoNormal">I used two different methods for creating the stars. One uses less HTML, and one uses more. For the small stars that show up when you make a rating, I wanted to use less HTML and used the sprite method to show the rating.<span> </span>But it does the same thing as the rateWidth but determines the background positioning based on the rating provided.</p>
<p class="MsoNormal">
<p class="MsoNormal"><span style="font-family: Wingdings;"><span>ß</span></span><span> </span>jscript starSprite <span style="font-family: Wingdings;"><span>à</span></span></p>
<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal">3. hover function *JQuery</p>
<p class="MsoNormal">The hover function will detect the cursor hovering over our &lt;li&gt;’s and the value of it and then send the value to the rateWidth function to get our width. It then assigns the width to the #rating_on div.</p>
<p class="MsoNormal">
<p class="MsoNormal"><span style="font-family: Wingdings;"><span>ß</span></span> hover function <span style="font-family: Wingdings;"><span>à</span></span></p>
<p class="MsoNormal">
<p class="MsoNormal">4. mouseout function</p>
<p class="MsoNormal">The mouseout function does just that, tells what stars should be showing on mouseout. But we do not want the stars to be reset every time we go off the stars, especially if we already selected a rating.<span> </span>So we grab the value of our #rating div and if it is “not rated” we set our width to 0px but if it doesn’t equal “not rated” we set the width of it’s set value.<span> </span>This way if you have selected a rating it defaults back to it when you mouseout.</p>
<p class="MsoNormal">
<p class="MsoNormal"><span style="font-family: Wingdings;"><span>ß</span></span> <span style="font-family: Wingdings;"><span>à</span></span></p>
<p class="MsoNormal">
<p class="MsoNormal">5.<span> </span>click function</p>
<p class="MsoNormal">This function has a little bit more going on than the other ones. When you click the &lt;li&gt; it first grabs the value of the clicked &lt;li&gt; assigns it to the #rating div, uses starSprite function to assign the background position for the #small_stars div, then hides the #rating_btns div, and the #rating_on div. Once hidden, it nicely fades in the #rated div.</p>
<p class="MsoNormal">
<p class="MsoNormal">6. edit function</p>
<p class="MsoNormal">This function just hides the #rated div and fades in the two divs we just hid. The #rating_div and the #rating_btns div.</p>
<p class="MsoNormal">
<p class="MsoNormal">Bam&#8230; we’re done.</p>
<p class="MsoNormal">
<p class="MsoNormal">Here is the completed code for your viewing pleasure.</p>
<p class="MsoNormal"><span style="font-family: Wingdings;"><span>ß</span></span> html <span style="font-family: Wingdings;"><span>à</span></span></p>
<p class="MsoNormal"><span style="font-family: Wingdings;"><span>ß</span></span> JQuery <span style="font-family: Wingdings;"><span>à</span></span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/jquery-star-comment-rating/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>
