<?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>Paul Gueller &#187; JavaScript</title>
	<atom:link href="http://paulgueller.com/category/web/javascript-web/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulgueller.com</link>
	<description>Interactive. Web. Solutions.</description>
	<lastBuildDate>Sat, 23 Jul 2011 15:33:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Parse the Querystring with jQuery</title>
		<link>http://paulgueller.com/2011/04/26/parse-the-querystring-with-jquery/</link>
		<comments>http://paulgueller.com/2011/04/26/parse-the-querystring-with-jquery/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 17:19:14 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=426</guid>
		<description><![CDATA[In a number of the web applications I have recently been working on, I have found it necessary to dissect the URL and access the various parts of the querystring. While the window.location object already has some useful properties, I wanted to be able to reference the indices using bracket or dot notation so I [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2011/04/26/parse-the-querystring-with-jquery/' addthis:title='Parse the Querystring with jQuery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>In a number of the web applications I have recently been working on, I have found it necessary to dissect the URL and access the various parts of the querystring. While the <code>window.location</code> object already has some <a href="http://developer.mozilla.org/en/DOM/window.location" title="Honestly, I didn't even know some of these existed">useful properties</a>, I wanted to be able to reference the indices using bracket or <a href="http://www.javascripttoolbox.com/bestpractices/#squarebracket" title="JavaScript best practices">dot notation</a> so I put together this handy plugin for my favorite JavaScript library, jQuery.</p>
<h3>Plugin</h3>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  parseQuerystring<span style="color: #339933;">:</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: #003366; font-weight: bold;">var</span> nvpair <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> qs <span style="color: #339933;">=</span> window.<span style="color: #660066;">location</span>.<span style="color: #660066;">search</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'?'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> pairs <span style="color: #339933;">=</span> qs.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>pairs<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> v<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> pair <span style="color: #339933;">=</span> v.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      nvpair<span style="color: #009900;">&#91;</span>pair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</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: #000066; font-weight: bold;">return</span> nvpair<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<h3>Usage</h3>
<p>Assuming the URL is <em>http://mydomain.com/page.html?foo=bar&#038;somevalue=myvalue</em>, you can either access an index directly <code>jQuery.parseQuerystring().foo</code>, or by setting a variable, like this:


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> qs <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">parseQuerystring</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//qs['foo'] == &quot;bar&quot;</span>
<span style="color: #006600; font-style: italic;">//qs.somevalue == &quot;myvalue&quot;</span></pre></div></div>


</p>
<p>The goal of extending the jQuery object with this utility (meaning that it does not require a selected set of elements, and in this case does not even require an argument) was flexibility, however it can easily be converted to a function in the global namespace. If you would rather download the files, they are zipped up and ready (<a href="http://paulgueller.com/download/parseQuerystring.zip"><img alt="document zipper Parse the Querystring with jQuery" title="zip" class="download-icon" src="http://paulgueller.com/wp-content/plugins/download-monitor/img/filetype_icons/document-zipper.png" />ParseQuerystring jQuery Plugin</a>).</p>
<p>Are there additional operations you&#8217;d like to see added to this, or relating to the URL and querystring? Let me know in the comments.</p>
<p><strong>Update:</strong> <a href="https://gist.github.com/1101534">Code posted to GitHub as a Gist snippet</a></p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2011/04/26/parse-the-querystring-with-jquery/' addthis:title='Parse the Querystring with jQuery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2011/04/26/parse-the-querystring-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Toggle Text Field Values with jQuery</title>
		<link>http://paulgueller.com/2009/09/18/toggle-text-field-values-with-jquery/</link>
		<comments>http://paulgueller.com/2009/09/18/toggle-text-field-values-with-jquery/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 17:00:09 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[semantic web]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=176</guid>
		<description><![CDATA[UPDATED: Project moved to Git! I saw this post on the CSS Tricks Snippet Feed which addresses a commonly desired form behavior: to provide default text in an INPUT element that disappears when the user enters that field. The example provided works, but I have a couple issues with it: Uses inline JavaScript, and must [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/09/18/toggle-text-field-values-with-jquery/' addthis:title='Toggle Text Field Values with jQuery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p><em><a href="#git_togglefield">UPDATED: Project moved to Git!</a></em></p>
<p>I saw <a title="Clear Field on Focus" href="http://css-tricks.com/snippets/javascript/clear-field-on-focus/">this post</a> on the <a title="CSS Tricks Snippet Feed | Yahoo! Pipes" href="http://feeds.feedburner.com/CSS-TricksSnippets">CSS Tricks Snippet Feed</a> which addresses a commonly desired form behavior: to provide default text in an <kbd>INPUT</kbd> element that disappears when the user enters that field. The example provided works, but I have a couple issues with it:</p>
<ol>
<li>Uses inline JavaScript, and must be reapplied to each element affected</li>
<li>Repeats the contents of the <kbd>value</kbd> attribute</li>
<li>The default text is not replaced if the user exits the field without entering new data</li>
</ol>
<p>So I created a possible solution, using jQuery:</p>
<h3>HTML</h3>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Place default text here&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></td></tr></table></div>



<h3>JavaScript</h3>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<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: #3366CC;">'input[type=&quot;text&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;">attr</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'title'</span><span style="color: #339933;">,</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;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
      .<span style="color: #000066;">focus</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</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;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</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;">val</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">''</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</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;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">||</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;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">' '</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;">val</span><span style="color: #009900;">&#40;</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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</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>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>This script first iterates over each of the text input to assign a semantic text attribute, helpful not only in storing the default value, but also providing a tool-tip for reference as the user interacts with the page. It then assigns behaviors for both the <kbd>onfocus</kbd> and <kbd>onblur</kbd> events, eliminating the need to respecify data for comparison. The script is cleanly separated from the markup and, using jQuery, additional specifications may be made so as to only affect children of a particular <kbd>FIELDSET</kbd> or only those that possess a certain class.</p>
<p>I hope you find this snippet useful, and feel free to comment if you have additional information to share.</p>
<hr />
<h2>UPDATED!</h2>
<p>We, as designers and developers, cannot help but go back to review our sites and code to make updates and revisions as our skills, philosophies and tastes change. In this spirit, I would like to offer an alternative to the above JavaScript snippet. The one above, in my opinion, is lacking in the following ways:</p>
<ol>
<li>Applies the behavior to all <code>input[type="text"]</code> elements indiscriminantly.</li>
<li>Overwrites any existing title attribute content</li>
<li>Does not account for existing text field values resulting from pre-population or validation.</li>
</ol>
<p>So with that in mind, here&#8217;s the new solution:</p>
<h3>HTML</h3>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Place default assistive text here (e.g. First Name)&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Default assistive text (e.g. E-Mail Address)&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;invalid@ddr.ess&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></td></tr></table></div>



<h3>jQuery Plugin</h3>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">toggleField</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</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: #003366; font-weight: bold;">var</span> $this <span style="color: #339933;">=</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: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;&amp;</span> $this.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      $this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    $this.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focus blur'</span><span style="color: #339933;">,</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: #003366; font-weight: bold;">var</span> $this <span style="color: #339933;">=</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: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> $this.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">||</span> $this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</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>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<h3>JavaScript</h3>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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: #3366CC;">'input[type=&quot;text&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggleField</span><span style="color: #009900;">&#40;</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></td></tr></table></div>



<p>By converting the behavior into a plugin, it becomes chainable and more flexible. Perhaps in a future version it would be useful accommodate additional field types or <code>textarea</code> elements.  I have also packaged the plugin for download (<a href="http://paulgueller.com/download/togglefield.zip"><img alt="document zipper Toggle Text Field Values with jQuery" title="zip" class="download-icon" src="http://paulgueller.com/wp-content/plugins/download-monitor/img/filetype_icons/document-zipper.png" />ToggleField jQuery Plugin</a>). I look forward to seeing your questions or suggestions in the comments below!</p>
<h2 id="git_togglefield">Project Moved to Git</h2>
<p>After further review and consideration, I decided to make some more changes to the plug-in to take advantage of some of the new features promoted in HTML5. Specifically the <a href="http://www.w3schools.com/html5/att_input_placeholder.asp"><code>placeholder</code></a> attribute, since this is essentially the behavior that we are trying to mimic. Here is an example:</p>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span>&gt;</span>Email:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Enter a valid email address&quot;</span> placeholder<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;account@domain.tld&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>



<p>The previous zip file will remain available above, but the <a href="https://github.com/oomlaut/toggleField.jquery.js">toggleField.jquery.js</a> project updates will progress on GitHub instead. Thanks to everyone for your suggestions and support!</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/09/18/toggle-text-field-values-with-jquery/' addthis:title='Toggle Text Field Values with jQuery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2009/09/18/toggle-text-field-values-with-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Howto: Create a jQuery Plugin</title>
		<link>http://paulgueller.com/2009/02/19/howto-create-a-jquery-plugin/</link>
		<comments>http://paulgueller.com/2009/02/19/howto-create-a-jquery-plugin/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 19:55:53 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=101</guid>
		<description><![CDATA[Jeffrey Way provides a step-by-step screencast, accompanied by source code and plenty of documentation in the post titled You Still Can’t Create a jQuery Plugin? &#8211; NETTUTS.<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/02/19/howto-create-a-jquery-plugin/' addthis:title='Howto: Create a jQuery Plugin ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Jeffrey Way provides a step-by-step screencast, accompanied by source code and plenty of documentation in the post titled <a href="http://net.tutsplus.com/videos/screencasts/you-still-cant-create-a-jquery-plugin/">You Still Can’t Create a jQuery Plugin? &#8211; NETTUTS</a>.</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/02/19/howto-create-a-jquery-plugin/' addthis:title='Howto: Create a jQuery Plugin ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2009/02/19/howto-create-a-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Innovative Layouts and Content Transitions with JavaScript</title>
		<link>http://paulgueller.com/2009/02/07/innovative-layouts-and-content-transitions-with-javascript/</link>
		<comments>http://paulgueller.com/2009/02/07/innovative-layouts-and-content-transitions-with-javascript/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 20:46:17 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[noupe]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=52</guid>
		<description><![CDATA[I started following @jquery on Twitter sometime ago, and they have provided a lot of great links and information. One interesting link is to an article about methods for presenting information and creating systems to enhance user experience: Delivering informative structure is the primary task an interactive user interface should be able to cope with. [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/02/07/innovative-layouts-and-content-transitions-with-javascript/' addthis:title='Innovative Layouts and Content Transitions with JavaScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>I started following <a title="News &amp; updates from the jQuery team." href="http://twitter.com/jquery">@jquery</a> on Twitter sometime ago, and they have provided a lot of great links and information.</p>
<p>One interesting link is to an article about methods for presenting information and creating systems to enhance user experience:</p>
<blockquote>
Delivering informative structure is the primary task an interactive user interface should be able to cope with. The more intuitive layout structure is designed, the better users can understand the content.
</blockquote>
<p><a title="10 Smart Javascript Techniques For Manipulating Content" href="http://www.noupe.com/javascript/10-smart-javascript-techniques-for-manipulating-content.html">Read the full article on Noupe</a>.</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/02/07/innovative-layouts-and-content-transitions-with-javascript/' addthis:title='Innovative Layouts and Content Transitions with JavaScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2009/02/07/innovative-layouts-and-content-transitions-with-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Examples of jQuery In Action</title>
		<link>http://paulgueller.com/2009/01/28/examples-of-jquery-in-action/</link>
		<comments>http://paulgueller.com/2009/01/28/examples-of-jquery-in-action/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 20:41:28 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=86</guid>
		<description><![CDATA[The jQuery foundation has created a new site showcasing designs that Use jQuery. They currently have only about 30 samples organized by effect/function category, but they do accept submissions so show off that great interface or behavior that you&#8217;ve created!<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/01/28/examples-of-jquery-in-action/' addthis:title='Examples of jQuery In Action ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>The jQuery foundation has created a new site showcasing designs that <a href="http://usejquery.com/">Use jQuery</a>. They currently have only about 30 samples organized by effect/function category, but they do accept submissions so <a title="Submit your site" href="http://www.noupe.com/javascript/10-smart-javascript-techniques-for-manipulating-content.html">show off</a> that great interface or behavior that you&#8217;ve created!</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/01/28/examples-of-jquery-in-action/' addthis:title='Examples of jQuery In Action ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2009/01/28/examples-of-jquery-in-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>25 Tips to Developing with jQuery</title>
		<link>http://paulgueller.com/2009/01/18/25-tips-to-developing-with-jquery/</link>
		<comments>http://paulgueller.com/2009/01/18/25-tips-to-developing-with-jquery/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 15:50:06 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=61</guid>
		<description><![CDATA[Jon Hobbs-Smith has compiled a list of 25 tips to making your jQuery-powered applications easier to script and faster loading.<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/01/18/25-tips-to-developing-with-jquery/' addthis:title='25 Tips to Developing with jQuery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Jon Hobbs-Smith from the UK web development firm <a title="Web Design by TVI" href="http://www.tvidesign.co.uk/">TVI Design</a> has compiled a <a title="25 Tips to Improve Your jQuery" href="http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx">list of 25 tips</a> to making your jQuery-powered applications easier to script and faster loading. While some of the items may be considered common knowledge (such as <code>return false;</code> for click events to prevent default behavior) the list provides excellent links and resources to people interested in using the <a title="jQuery" href="http://jquery.com/">Write Less, Do More JavaScript Library</a>.</p>
<p>Considering almost all the <a title="Update to v1.3.0" href="http://docs.jquery.com/Release:jQuery_1.3">recent updates</a> to the framework relate to improving speed, why not take fullest advantage of them in making your application as responsive as possible?</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2009/01/18/25-tips-to-developing-with-jquery/' addthis:title='25 Tips to Developing with jQuery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2009/01/18/25-tips-to-developing-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pushup Makes the Web Stronger</title>
		<link>http://paulgueller.com/2008/12/19/pushup-makes-the-web-stronger/</link>
		<comments>http://paulgueller.com/2008/12/19/pushup-makes-the-web-stronger/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 05:01:36 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[nick stakenburg]]></category>
		<category><![CDATA[pushup]]></category>
		<category><![CDATA[standards compliance]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=38</guid>
		<description><![CDATA[Give your users a better web experience and move the web forward by helping users upgrade their outdated browsers A subtle upgrade link is shown when people visit your website using an outdated version of Internet Explorer, Firefox, Safari or Opera.<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/12/19/pushup-makes-the-web-stronger/' addthis:title='Pushup Makes the Web Stronger ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Every web developer that I know is <a title="IE Voodoo Doll Tutorial" href="http://chisa.deviantart.com/art/tutorial-IE-voodoo-doll-65352093">sick and tired</a> of making compromises and hacks to accommodate <a title="Petition to &quot;Make Internet Explorer Standards Compliant&quot;" href="http://www.petitiononline.com/IE7STAN/petition.html">Internet Explorer 6</a> and other browsers that are not <a title="About the World Wide Web Consortium (W3C)" href="http://www.w3.org/Consortium/Overview.html">standards compliant</a>. While <a title="Will we ever be able to fully utilize CSS2?" href="http://www.css3.info/graceful-degradation/">graceful degradation</a> (or <a title="Two sides of the same coin" href="http://accessites.org/site/2007/02/graceful-degradation-progressive-enhancement/">progressive enhancement</a>, depending on which philosophy you subscribe to) will continue to be a par for the course for the forseeable future, it would be great if we could fully take advantage of the available technologies and minimize crosss-browser tesing costs in our project budgets.</p>
<p>To this goal, <a title="Nick Stakenburg : Web Developer and Illustrator" href="http://www.nickstakenburg.com/">Nick Stakenburg</a> released a script that gently alerts the user that their browser could use an upgrade. <a title="Give your users a better web experience" href="http://www.pushuptheweb.com/">Pushup</a> detects the version of the client and briefly flashes a notice with a link to download an update. The entire package is fairly lightweight (only 11kb, zipped) and includes the images, sylesheets and JavaScript files to run. Implementation and customization information is provided on the download site, in addition to ports of the function for <a title="Psychcf dojox.pushup" href="http://psychcf.dojotoolkit.org/pushup/">dojo</a> and <a title="Uses jQuery fade effect instead of prototype's" href="http://stuartloxton.com/jquery-pushup/">jQuery</a>.</p>
<p>This doesn&#8217;t really help users whose IT departments <a title="WHY?!?!" href="http://www.itedge.net/blog/2006/09/18/prevent-automatic-update-to-internet-explorer-7-ie7/">prohibit them from updating</a>, but if it helps those who are unaware that there is a better web experience to be had then it is worthy of praise and support.</p>
<hr />
<h2>UPDATE</h2>
<p><strong>VICTORY!!!</strong> Even Microsoft is denouncing IE6. Track the downfall of this archaic software at <a href="http://ie6countdown.com/">IE6 Countdown</a>.</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/12/19/pushup-makes-the-web-stronger/' addthis:title='Pushup Makes the Web Stronger ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2008/12/19/pushup-makes-the-web-stronger/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sIFR + jQuery = Custom Typography Without Image Replacement</title>
		<link>http://paulgueller.com/2008/12/16/sifr-jquery-custom-typography-without-image-replacement/</link>
		<comments>http://paulgueller.com/2008/12/16/sifr-jquery-custom-typography-without-image-replacement/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 22:41:56 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plug-ins]]></category>
		<category><![CDATA[sift]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=36</guid>
		<description><![CDATA[Sick of reusing the same few "web-safe" fonts? Tired of resorting to turning those headlines into images only to revise them whenever there's a copy change? Utilize the flexibility of sIFR with the power of jQuery to insert dynamic vector typefaces into your layout with a lightweight plug-in.<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/12/16/sifr-jquery-custom-typography-without-image-replacement/' addthis:title='sIFR + jQuery = Custom Typography Without Image Replacement ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t heard of it already, <a title="Scalable Inman Flash Replacement" href="http://novemberborn.net/sifr">sIFR</a> lets you appease all those designers by integrating custom fonts onto your standards-compliant web page without turning them into images. On its own, it&#8217;s not a small or straightforward undertaking, requiring a number of additional CSS and JavaScript files to function. However, the recent release of the <a title="Replace text in a web page dynamically through library extension" href="http://jquery.thewikies.com/sifr/">sIFR jQuery plug-in</a> should make it more accessible to developers:</p>
<blockquote>First, jQuery makes finding the item(s) that you want to replace as easy as using CSS. Then, the jQuery sIFR Plugin does all the work of figuring out the text, files, sizes, colors, and any other configurations needed for the conversion. The jQuery sIFR plugin is fully configurable and can choose how little or how much you want to customize the display of the sIFRed text. Finally, the jQuery Flash Plugin does a most excellent job of embedding the sIFR flash into your web page. After all is said and done, you should have beautiful sIFR replaced text with consistent behavior across all major browsers.</blockquote>
<p>All the resources are available for download from the <a title="jQuery Sifr Plugin by Jonathan Neal " href="http://jquery.thewikies.com/sifr/">developer&#8217;s site</a>, as well a simple API and usage examples for easy customization.</p>
<hr />
<h2>UPDATE</h2>
<p>While sIFR may have its uses it also has a number of serious drawbacks. Check out some of the emerging web typography technologies, including <a href="http://cufon.shoqolate.com/generate/">Cufón</a>, <a href="http://www.fontsquirrel.com/fontface/generator">@font-face</a> and <a href="http://typekit.com">Typekit</a>.</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/12/16/sifr-jquery-custom-typography-without-image-replacement/' addthis:title='sIFR + jQuery = Custom Typography Without Image Replacement ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2008/12/16/sifr-jquery-custom-typography-without-image-replacement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Evolution of Sizzle</title>
		<link>http://paulgueller.com/2008/12/12/the-evolution-of-sizzle/</link>
		<comments>http://paulgueller.com/2008/12/12/the-evolution-of-sizzle/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 19:58:15 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[john resig]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[sizzle]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/?p=29</guid>
		<description><![CDATA[jQuery founder discusses possibilities of CSS-based selector engine to extend major JavaScript libraries<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/12/12/the-evolution-of-sizzle/' addthis:title='The Evolution of Sizzle ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Among the many interesting things discussed in the <a title="Interview with John Resig, jQuery Creator" href="http://www.sitepoint.com/article/interview-john-resig/">interview</a> with Sitepoint, John Resig <a title="First reference on Ajaxian" href="http://ajaxian.com/archives/sizzle-john-resig-has-a-new-selector-engine">again</a> brought up a project titled <a title="A sizzlin' hot selector engine." href="http://github.com/jeresig/sizzle/tree/master">Sizzle</a>. No, he&#8217;s not talking about adding <strong>POW BANG SHAZAM</strong> to our web layouts; it&#8217;s an initiative to create standardized and easily-implemented CSS-based selectors for JavaScript.</p>
<p>Aside from its lightweight and extensible nature, jQuery&#8217;s ability to easily assign behaviors and attributes to custom-created arrays of elements without much hassle is one of its most appealing features. Using a similar scheme for other libraries, frameworks or even in stand-alone cases would not only simplify programming (goodbye <code>document.getElementsByTagName</code> &#8220;for&#8221; loops!) but would improve the language as a whole by making scripts more readable and accessible.</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/12/12/the-evolution-of-sizzle/' addthis:title='The Evolution of Sizzle ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2008/12/12/the-evolution-of-sizzle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using jQuery for DHTML Drop-Down Menus</title>
		<link>http://paulgueller.com/2008/04/17/using-jquery-for-dhtml-drop-down-menus/</link>
		<comments>http://paulgueller.com/2008/04/17/using-jquery-for-dhtml-drop-down-menus/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 14:54:38 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blog.paulgueller.com/2008/04/17/using-jquery-for-dhtml-drop-down-menus/</guid>
		<description><![CDATA[You may have heard of the Suckerfish Dropdowns featured on A List Apart (which use CSS and JavaScript along with valid HTML to create vertical or horizontal &#8220;drop-down&#8221; menus) and the the extended revised version Son of Suckerfish, but if you&#8217;re already using the jQuery library on your site the code to mimic the :hover [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/04/17/using-jquery-for-dhtml-drop-down-menus/' addthis:title='Using jQuery for DHTML Drop-Down Menus ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>You may have heard of the <a href="http://www.alistapart.com/articles/dropdowns/">Suckerfish Dropdowns</a> featured on A List Apart (which use CSS and JavaScript along with valid HTML to create vertical or horizontal &#8220;drop-down&#8221; menus) and the the extended revised version <a href="http://www.htmldog.com/articles/suckerfish/">Son of Suckerfish</a>, but if you&#8217;re already using the <a href="http://jquery.com/">jQuery</a> library on your site the code to mimic the <kbd>:hover</kbd> pseudo-class gets even simpler.</p>
<p>Instead of:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">sfHover <span style="color: #339933;">=</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: #003366; font-weight: bold;">var</span> sfEls <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;nav&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;LI&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>sfels .<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">&gt;</span>
    sfEls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">onmouseover</span><span style="color: #339933;">=</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">className</span><span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot; sfhover&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    sfEls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">onmouseout</span><span style="color: #339933;">=</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">className</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">className</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; sfhover<span style="color: #000099; font-weight: bold;">\\</span>b&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#41;</span> window.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;onload&quot;</span><span style="color: #339933;">,</span> sfHover<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>sfels<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>



<p>You only need:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nav li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sfhover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//mouseover</span>
 <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</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;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sfhover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//mouseout</span>
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>or, simpler yet:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nav li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mouseover mouseout&quot;</span><span style="color: #339933;">,</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;">toggleClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sfhover'</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></td></tr></table></div>



<p>Such is the beauty of using css-style selectors to build an array of affected elements. Of course, you must make sure the code is wrapped in <kbd>$(document).ready(function(){…});</kbd>, but there is no need to modify the <em>window.onload</em> event in this example. Otherwise, refer to the code provided in the above examples to get your markup and formatting styles in place.</p><div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://paulgueller.com/2008/04/17/using-jquery-for-dhtml-drop-down-menus/' addthis:title='Using jQuery for DHTML Drop-Down Menus ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://paulgueller.com/2008/04/17/using-jquery-for-dhtml-drop-down-menus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

