Skip to content

Instantly share code, notes, and snippets.

@rmcvey
Last active December 14, 2015 19:28
Show Gist options
  • Save rmcvey/5136582 to your computer and use it in GitHub Desktop.
Save rmcvey/5136582 to your computer and use it in GitHub Desktop.
$.fn.placeholder = function(text){
if(typeof text !== 'undefined'){
this.attr('data-placeholder', text);
} else {
return this.attr('data-placeholder');
}
var that = $(this)
if(that.val('')){
that.val(text);
}
that.focus(function(){
if($(this).val() === text)
{
that.val('')
}
}).blur(function(){
if(that.val() === ''){
that.val(text)
}
})
return that;
}
// example
var $fn = $('#first_name');
$fn.placeholder('First Name');
$('#form').submit(function(){
if($fn.val() === $fn.placeholder()){
return false;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment