Skip to content

Instantly share code, notes, and snippets.

@radius
Created May 16, 2012 15:30
Show Gist options
  • Save radius/2711306 to your computer and use it in GitHub Desktop.
Save radius/2711306 to your computer and use it in GitHub Desktop.
Input Placeholder jQuery Plugin
$.fn.inputPlaceholder = function(options){
return $(this).each(function() {
var options = jQuery.extend({
text: $(this).attr('placeholder')
},options);
if($(this).val() == '') {
$(this).val(options.text);
}
$(this)
.focus(function(e){
if($(this).val() == options.text){
$(this).val('');
}
})
.blur(function(e){
if (this.value == '') {
this.value = options.text;
}
});
});
}
@radius
Copy link
Author

radius commented Oct 23, 2012

previous version didnt work for multiple instances on one page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment