Skip to content

Commit

Permalink
Added class="placeholder" to elements currently showing their placeho…
Browse files Browse the repository at this point in the history
…lder text
  • Loading branch information
mathiasbynens committed Jan 20, 2010
1 parent b230407 commit b68ab04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ This plugin was based on a code snippet by [Paul Irish](http://paulirish.com/),

$('input').placeholder();

### CSS

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 { color: #000; }
.placeholder { color: #666; }

## Notes

The plugin automatically checks if the browser supports the HTML5 placeholder attribute for inputs natively. If this is the case, the plugin won’t do anything.
Expand Down
4 changes: 2 additions & 2 deletions jquery.placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// 2) Once every time the focusout() is triggered.
function setPlaceholder($elem) {
if ($elem.val() === '') {
$elem.val($elem.attr('placeholder'));
$elem.addClass('placeholder').val($elem.attr('placeholder'));
};
};
function preventSubmit($elem) {
Expand Down Expand Up @@ -44,7 +44,7 @@
});
$input.focusin(function() {
if ($input.val() === $input.attr('placeholder')) {
$input.val('');
$input.removeClass('placeholder').val('');
};
}).focusout(function() {
setPlaceholder($input);
Expand Down
2 changes: 1 addition & 1 deletion jquery.placeholder.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b68ab04

Please sign in to comment.