﻿<?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>Travis Miller &#187; placeholder</title>
	<atom:link href="http://www.electrumdigital.com/tag/placeholder/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.electrumdigital.com</link>
	<description>Web Developer for Hire</description>
	<lastBuildDate>Thu, 22 Jul 2010 14:17:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simulating HTML5&#039;s placeholder attribute with jQuery</title>
		<link>http://www.electrumdigital.com/2009/10/simulating-html5s-placeholder-attribute-with-jquery/</link>
		<comments>http://www.electrumdigital.com/2009/10/simulating-html5s-placeholder-attribute-with-jquery/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 20:51:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AJAX & JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[placeholder]]></category>

		<guid isPermaLink="false">http://www.electrumdigital.com/?p=191</guid>
		<description><![CDATA[I recently discussed the placeholder attribute in HTML5. Today, I needed exactly such a behavior for a site I'm working on, so I knocked together a reusable, unobtrusive solution with jQuery.

Simply include this code (and jQuery, of course) on your page, and assign the placeholder text as the title attribute of the control. Example:

&#60;input type=&#34;text&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>I recently <a href="http://www.electrumdigital.com/2009/10/forms-in-html5/">discussed</a> the <code class="html">placeholder</code> attribute in <acronym title="HyperText Markup Language">HTML</acronym>5. Today, I needed exactly such a behavior for a site I'm working on, so I knocked together a reusable, unobtrusive solution with jQuery.</p>
<p><span id="more-191"></span></p>
<p>Simply include this code (and jQuery, of course) on your page, and assign the placeholder text as the <code class="html">title</code> attribute of the control. 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;">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;keywords&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Search&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>The script also assigns the class <code class="css">placeholder</code> to the control when the placeholder text is present, so you can style it differently if you like (for example, you may wish to gray out the text).</p>
<p>The code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Unobtrusively set up placeholder behaviors on all text inputs for which
 * the title attribute has been set. The title text will be used as the
 * placeholder text.
 * @author Travis Miller
 * @link http://www.electrumdigital.com/
 */</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>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[type=text][title],textarea[title]&quot;</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> showPlaceholder <span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// initialize each control on page load</span>
        .<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span> showPlaceholder <span style="color: #009900;">&#41;</span>
        .<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span> hidePlaceholder <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</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;">&quot;input[type=text][title],textarea[title]&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> hidePlaceholder <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>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> showPlaceholder<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> $control <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: #003366; font-weight: bold;">var</span> placeholderText <span style="color: #339933;">=</span> $control.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;title&quot;</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> $control.<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;">&quot;&quot;</span> <span style="color: #339933;">||</span> $control.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> placeholderText <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	$control.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;placeholder&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $control.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>placeholderText<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: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> hidePlaceholder<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> $control <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> $control.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> $control.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	$control.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;placeholder&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	$control.<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>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.electrumdigital.com/2009/10/simulating-html5s-placeholder-attribute-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
