-
-
Save naterkane/345575 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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'); | |
} | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input.placeholder { | |
color:#AAA; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment