Skip to content

Instantly share code, notes, and snippets.

@Gaya
Created March 19, 2012 15:00
Show Gist options
  • Save Gaya/2115385 to your computer and use it in GitHub Desktop.
Save Gaya/2115385 to your computer and use it in GitHub Desktop.
Placeholder script jQuery
/*
* Short jQuery method of making placeholders for all the browsers.
*
* Use the following HTML markup to make this work:
* <input type="text" class="placeholder" value="Your name" data-standard="Your name" />
*/
$(".placeholder").focus(function () {
if ($(this).val() == $(this).attr("data-standard")) {
$(this).val("").addClass("active"); //Add class for other styling
}
}).blur(function () {
if ($(this).val() == $(this).attr("data-standard") || $(this).val() == "") {
$(this).val($(this).attr("data-standard")).removeClass("active");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment