<?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>benwatts.ca &#187; jquery</title>
	<atom:link href="http://benwatts.ca/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://benwatts.ca</link>
	<description>Designer and Frontend Developer in Ottawa, Canada</description>
	<lastBuildDate>Fri, 22 Jul 2011 19:00:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>jQuery Input Text Replacement</title>
		<link>http://benwatts.ca/2008/jquery-input-text-replacement/</link>
		<comments>http://benwatts.ca/2008/jquery-input-text-replacement/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 18:55:33 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://localhost/benwatts.ca/?p=141</guid>
		<description><![CDATA[Edit (July 1, 2011): This snippet has been dated for years. A Modern Approach If you need something quick that targets modern browsers you might want to consider using the HTML5 placeholder attribute instead of a javascript solution. Cross-browser support isn&#8217;t the best (it doesn&#8217;t look like IE9 supports it at all, but if the [...]]]></description>
			<content:encoded><![CDATA[<p><strong class="notice">Edit (July 1, 2011): </strong>This snippet has been dated for <em>years</em>. </p>
<h2>A Modern Approach</h2>
<p>If you need something quick that targets modern browsers you might want to consider using the HTML5 <em>placeholder</em> attribute instead of a javascript solution. Cross-browser support isn&#8217;t the best (it doesn&#8217;t look like IE9 supports it at all, but if the placeholder text isn&#8217;t critical to the functionality it might be the right solution.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> placeholder<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Search&quot;</span> &nbsp;<span style="color: #66cc66;">/</span>&gt;</span></div></div>
<p><a href="http://diveintohtml5.org/forms.html#placeholder">Further reading</a> on the <em>placeholder</em> attribute. </p>
<p>If that won&#8217;t do it, check out this <a href="http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text" target="_blank">Cross-Browser HTML5 Placeholder Text on Web Designer Wall</a> if you&#8217;re looking for something more modern.</p>
<p>Finally, you can do it with jQuery (or plain ol&#8217; Javascript) as my original post from 2008 demonstrates&#8230;</p>
<p>Thought I&#8217;d save this handy dandy function for later.<br />
Makes the text in an input disappear when you click on the input.</p>
<h2>The Function</h2>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> textReplacement<span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;">var</span> originalvalue <span style="color: #339933;">=</span> input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;input.<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><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>input.<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: #339933;">===</span> originalvalue <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</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><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;input.<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><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>input.<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: #339933;">===</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>originalvalue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<h2>Using It</h2>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">textReplacement<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#inputname'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p><script type="text/javascript">// <![CDATA[
window.onload = function(){ 
  function textReplacement(input){var originalvalue = input.val();input.focus( function(){if( $.trim(input.val()) == originalvalue ){ input.val(''); }});input.blur( function(){if( $.trim(input.val()) == '' ){ input.val(originalvalue); }});}$(document).ready( function(){textReplacement($('#inputname'));});
}
// ]]&gt;</script></p>
<h2>Example</h2>
<input id="inputname" style="padding: 3px; width: 200px;" value="Click to Disappear" />
]]></content:encoded>
			<wfw:commentRss>http://benwatts.ca/2008/jquery-input-text-replacement/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>jQuery Random Colour Generator</title>
		<link>http://benwatts.ca/2008/jquery-random-colour-generator/</link>
		<comments>http://benwatts.ca/2008/jquery-random-colour-generator/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 16:26:35 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[sandbox]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.benwatts.ca/?p=12</guid>
		<description><![CDATA[I can&#8217;t remember the inspiration for this crazy thing, but I&#8217;m sure somewhere out there someone is looking for a random colour generator that is done in jQuery. So if you&#8217;re feeling in the mood to have a randomly changing colour &#8230; this is the script for you! Essentially it&#8217;s just generating a random number [...]]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t remember the inspiration for this crazy thing, but I&#8217;m sure somewhere out there someone is looking for a random colour generator that is done in jQuery.</p>
<p>So if you&#8217;re feeling in the mood to have a randomly changing colour &#8230; this is the script for you! Essentially it&#8217;s just generating a random number between 0 and 255 for red, green, and blue. It then uses CSS to change the colour property of an element (that&#8217;s easily customizable by you).</p>
<p>So <a href="/sandbox/jquery-colourific/">check out the demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://benwatts.ca/2008/jquery-random-colour-generator/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

