Skip to content

Instantly share code, notes, and snippets.

@ronnieduke
Last active July 11, 2017 15:11
Show Gist options
  • Save ronnieduke/ff539714f61bdaf431fb to your computer and use it in GitHub Desktop.
Save ronnieduke/ff539714f61bdaf431fb to your computer and use it in GitHub Desktop.
jQuery Toggle Placeholder
// Placeholder Toggle jQuery Extension
$.fn.togglePlaceholder = function() {
return this.each(function() {
$(this)
.data("holder", $(this).attr("placeholder"))
.focusin(function(){
$(this).attr('placeholder','');
})
.focusout(function(){
$(this).attr('placeholder',$(this).data('holder'));
});
});
};
jQuery(document).ready(function($) {
// Toggle All Elements with Placeholder Attributes
$("[placeholder]").togglePlaceholder();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment