Skip to content

Instantly share code, notes, and snippets.

@perezd
Created December 1, 2010 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perezd/b38093206179651e4780 to your computer and use it in GitHub Desktop.
Save perezd/b38093206179651e4780 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.replaceholder = function(options) {
var $placeholder;
(this.length > 0) ? $this = $(this) : $this = $('input[placeholder]');
return $this.each(function() {
settings = jQuery.extend({
focusColor: '#000',
blurColor: '#aaa'
}, options);
var $placeholder = $(this);
if ($placeholder.length > 0) {
var attrPh = $placeholder.attr('placeholder');
$placeholder.attr('value', attrPh);
$placeholder.css('color',settings.blurColor)
.bind('focus', function() {
var $this = $(this);
if($this.val() === attrPh)
$this.val('').css('color',settings.focusColor);
}).bind('blur', function() {
var $this = $(this);
if($this.val() === '')
$this.val(attrPh).css('color',settings.blurColor);
});
}
});
};
})(jQuery);
jQuery(function($){
$(document).ready(function(){
if (!Modernizr.input.placeholder) { $("input[placeholder], textarea[placeholder]").replaceholder() }
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment