mudge / jquery_placeholder
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
277dfc6
| name | age | message | |
|---|---|---|---|
| |
README.markdown | ||
| |
jquery.placeholder.js | ||
| |
jquery.placeholder.min.js | ||
| |
test.html |
jQuery Placeholder Plugin
A plugin to make HTML5's placeholder attribute work in non-HTML5
browsers.
This started as an attempt to simplify my jQuery Form Example plugin by delegating functionality to the browser where possible.
Usage
Simply use the placeholder attribute on your input and textarea tags and include
jquery.placeholder.js somewhere in your page (you'll need jQuery as well, of course).
e.g.
<input type="text" placeholder="Username">
<textarea placeholder="Comment here..."></textarea>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.placeholder.js"></script>
Placeholder values in non-HTML5 browsers will be given the CSS class of _placeholder so
you can style them to mimic other browsers' defaults which for Safari seems to be something
like the following:
._placeholder { color: #aaa; }
If you want to customise the class name used, you'll have to stop the plugin from
automatically running itself by commenting out $($.placeholder.backwardsCompatibility);
towards the end of jquery.placeholder.js. You can then set the class name via
$.placeholder.className and call backwardsCompatibility() yourself.
e.g.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.placeholder.js"></script>
<script type="text/javascript">
$.placeholder.className = 'myPlaceholderCSSClass';
$.placeholder.backwardsCompatibility();
</script>

