http://mathiasbynens.be/demo/placeholder
<input type="text" name="name" placeholder="e.g. John Doe">
<input type="email" name="email" placeholder="e.g. [email protected]">
<input type="url" name="url" placeholder="e.g. http://mathiasbynens.be/">
<input type="tel" name="tel" placeholder="e.g. +32 472 77 69 88">
<input type="password" name="password" placeholder="e.g. h4x0rpr00fz">
<input type="search" name="search" placeholder="Search this site…">
<textarea name="message" placeholder="Your message goes here"></textarea>
$('input, textarea').placeholder();
The plugin automatically adds class="placeholder"
to the elements who are currently showing their placeholder text. You can use this to style placeholder text differently:
input, textarea { color: #000; }
.placeholder { color: #aaa; }
- Works in all A-grade browsers, including IE6.
- The plugin automatically checks if the browser natively supports the HTML5
placeholder
attribute forinput
andtextarea
elements. If this is the case, the plugin won’t do anything. If@placeholder
is only supported forinput
elements, the plugin will leave those alone and apply totextarea
s exclusively. (This is the case for Safari 4, Opera 11.00, and possibly other browsers.)
This plugin is dual licensed under the MIT and GPL licenses, just like jQuery itself.
Kudos to Paul Irish for his inspiring snippet in jQuery 1.4 Hawtness #1 and everyone from #jquery for the tips, ideas and patches.
– Mathias