jQuery-placeholder is a JavaScript shim to emulate the behavior of the HTML5 placeholder attribute where it isn't supported.
Include jquery.placeholder-x.x.js after jQuery has been included:
<script type="text/javascript" src="jquery-x.x.x.js"></script> <script type="text/javascript" src="jquery.browsersupport-x.x.js"></script>
Run the
$.placeholder()function on the document ready event:$(document).ready(function(){ $('input#search').placeholder(); });
Options may be passed to the $().placeholder() function via an optional hash parameter. Example:
$('input#search').placeholder({
onClass: 'on',
offClass: 'off',
placeholderSupport: featureSupport.placeholder
});
- onClass
- Class to be applied while
<input>is focused (falseor string; default'focused') - offClass
- Class to be applied while
<input>is blurred (falseor string; defaultfalse) - placeholderSupport
- Whether or not the
placeholderattribute is supported (boolean; default('placeholder' in document.createElement('input'))). Only define to avoid running feature test multiple times (e.g. if you are using jquery-featureSupport)