Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
$(function() {
// Clone HTML5's placeholder attribute functionality
$('input[placeholder]').each(function() {
// Store the placeholder text and then set the element's value
// TODO: Check to make sure value is empty before setting here
$(this).data('placeholder', $(this).attr('placeholder'));
$(this).val($(this).data('placeholder')).addClass('placeholder');
// Handle the removal/addition of the placeholder text on focus/blur
$(this).focus(function() {
if ($(this).val() == $(this).data('placeholder')) {
$(this).val('').removeClass('placeholder');
}
}).blur(function() {
if (!$(this).val().match(/\w/)) {
$(this).val($(this).data('placeholder')).addClass('placeholder');
}
});
});
});
input.placeholder {
color:#AAA;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment