Skip to content

Instantly share code, notes, and snippets.

@hagenburger
Created April 26, 2010 17:15

Revisions

  1. hagenburger revised this gist Oct 21, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions jQuery HTML5 placeholder fix.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // Released under MIT license: http://www.opensource.org/licenses/mit-license.php

    $('[placeholder]').focus(function() {
    var input = $(this);
    if (input.val() == input.attr('placeholder')) {
  2. hagenburger revised this gist Sep 29, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jQuery HTML5 placeholder fix.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ $('[placeholder]').focus(function() {
    }
    }).blur(function() {
    var input = $(this);
    if (input.val() == '') {
    if (input.val() == '' || input.val() == input.attr('placeholder')) {
    input.addClass('placeholder');
    input.val(input.attr('placeholder'));
    }
  3. hagenburger renamed this gist Apr 26, 2010. 1 changed file with 0 additions and 0 deletions.
  4. hagenburger created this gist Apr 26, 2010.
    20 changes: 20 additions & 0 deletions jQuery HTML5 placeholder fix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    $('[placeholder]').focus(function() {
    var input = $(this);
    if (input.val() == input.attr('placeholder')) {
    input.val('');
    input.removeClass('placeholder');
    }
    }).blur(function() {
    var input = $(this);
    if (input.val() == '') {
    input.addClass('placeholder');
    input.val(input.attr('placeholder'));
    }
    }).blur().parents('form').submit(function() {
    $(this).find('[placeholder]').each(function() {
    var input = $(this);
    if (input.val() == input.attr('placeholder')) {
    input.val('');
    }
    })
    });