Skip to content

Instantly share code, notes, and snippets.

@yomotsu
Created March 29, 2012 10:42
Show Gist options
  • Save yomotsu/2235766 to your computer and use it in GitHub Desktop.
Save yomotsu/2235766 to your computer and use it in GitHub Desktop.
polyfill for input@placeholder
(function($){
$(function(){
if(!Modernizr.input.placeholder){
var $i = $('input[placeholder]');
$i.each(function(){
var $that = $(this);
var text = $that.attr('placeholder');
$that.css({color:'#aaa'});
$that.val(text);
$that.bind('focus', function(){
var $that = $(this);
if(new RegExp('^' + text + '$').test($that.val())){
$that.val('');
$that.css({color:'#333'});
}
});
$that.bind('blur', function(){
if(new RegExp('^$').test($that.val())){
$that.val(text);
$that.css({color:'#333'});
}
});
});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment