Skip to content

Instantly share code, notes, and snippets.

@AndorChen
Created December 9, 2011 05:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndorChen/1450312 to your computer and use it in GitHub Desktop.
Save AndorChen/1450312 to your computer and use it in GitHub Desktop.
jQuery HTML5 Placeholder fix
/**
* jQuery.HTML5 placeholder - Placeholder plugin for input fields
* Written by Ludo Helder (ludo DOT helder AT gmail DOT com)
* Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
* Date: 2010/11/18
*
* @author Ludo Helder
* @version 1.0.1
*
**/
$(function(){
var d = "placeholder" in document.createElement("input");
if (!d){
$("input[placeholder]").each(function(){
$(this).val(element.attr("placeholder")).addClass('placeholder');
}).bind('focus',function(){
if ($(this).val() == element.attr('placeholder')){
$(this).val('').removeClass('placeholder');
}
}).bind('blur',function(){
if ($(this).val() == ''){
$(this).val(element.attr("placeholder")).addClass('placeholder');
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment