Skip to content

Instantly share code, notes, and snippets.

@keif
Created November 29, 2012 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keif/4172291 to your computer and use it in GitHub Desktop.
Save keif/4172291 to your computer and use it in GitHub Desktop.
Detect Placeholder support for form elements
function hasSupport(elem, attribute) {
return attribute in elem;
}
$('body').delegate('textarea', 'focus input change keydown keyup', function(e) {
var $textArea = $(this);
if (!hasSupport($textArea[0], 'placeholder')) {
var placeholderText = $textArea.attr("placeholder");
if (this.value === $textArea.data("placeholder")) {
this.value = "";
}
}
}).delegate('textarea', 'blur', function(e){
var $textArea = $(this);
if (!hasSupport($textArea[0], 'placeholder')) {
if (this.value === "") {
this.value = $textArea.data("placeholder");
$textArea.addClass('blur');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment