Skip to content

Instantly share code, notes, and snippets.

@hdragomir
Created March 18, 2011 11:09
Show Gist options
  • Save hdragomir/875903 to your computer and use it in GitHub Desktop.
Save hdragomir/875903 to your computer and use it in GitHub Desktop.

Revisions

  1. Horia Dragomir created this gist Mar 18, 2011.
    12 changes: 12 additions & 0 deletions $.fn.hint.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    $.fn.hint = function(hint){
    var val = $(this).eq(0).bind('focus', function(){
    $(this).removeClass('hinting');
    if($(this).val() == hint) $(this).val('');
    }).bind('blur', function(){
    if($(this).val() == '') $(this).addClass('hinting').val(hint);
    }).bind('change', function(){
    $(this).removeClass('hinting');
    }).val();
    if(! /\S/.test(val)) $(this).eq(0).val(hint).addClass('hinting');
    return this;
    }