Skip to content

Instantly share code, notes, and snippets.

@AndorChen
Created December 9, 2011 05:25
Show Gist options
  • Save AndorChen/1450312 to your computer and use it in GitHub Desktop.
Save AndorChen/1450312 to your computer and use it in GitHub Desktop.

Revisions

  1. AndorChen created this gist Dec 9, 2011.
    26 changes: 26 additions & 0 deletions jquery.html5.placeholder.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    /**
    * 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');
    }
    });
    }
    });