Skip to content

Instantly share code, notes, and snippets.

@quantizor
Created April 8, 2013 21:00
Show Gist options
  • Save quantizor/5340444 to your computer and use it in GitHub Desktop.
Save quantizor/5340444 to your computer and use it in GitHub Desktop.
Make placeholders disappear on focus, instead of when you start typing. (jQuery)
;(function($){
$(document).ready(function(){
var x = $('[placeholder]');
for( var i=0, len=x.length; i<len; i++ ){
x.eq(i).attr('data-placeholder', x.eq(i).attr('placeholder'));
}
x.on('focus', function(){ $(this).attr('placeholder', ''); })
x.on('blur', function(){ $(this).attr('placeholder', $(this).data('placeholder')); });
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment