Skip to content

Instantly share code, notes, and snippets.

@MikeRogers0
Forked from westonruter/gist:311373
Created February 6, 2012 12:02
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 MikeRogers0/1751763 to your computer and use it in GitHub Desktop.
Save MikeRogers0/1751763 to your computer and use it in GitHub Desktop.
jQuery fallback implementation of HTML5 placeholder attribute
if(!jQuery('<input PLACEHOLDER="1" />')[0].placeholder){ //Uppercase attr for IE
jQuery(':input[placeholder]').each(function(){
var $this = $(this);
if(!$this.val()){
$this.val($this.attr('placeholder'));
$this.addClass('input-placeholder');
}
}).live('focus', function(e){
var $this = $(this);
if($this.hasClass('input-placeholder')){
$this.val('');
$this.removeClass('input-placeholder')
}
}).live('blur', function(e){
var $this = $(this);
if(!$this.val()){
$this.addClass('input-placeholder');
$this.val($this.attr('placeholder'));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment