jQuery Default Input Text - placeholder HTML5


Posted by Ben Johnson on 21 March 2011 | 0 Comments

Tags:

jQuery plugin to provide a backwards compatible default input text fully browser compatible using JavaScript.

// Input Clear Default
    $('input[placeholder],textarea[placeholder]').each(function() {
        if($(this).val() === '') {
            $(this).val($(this).attr('placeholder'));    
        }
        $(this).focus(function() {
            if($(this).val() == $(this).attr('placeholder')) {
                $(this).val('');    
            }
        });
        $(this).blur(function() {
            if($(this).val() === '') {
                $(this).val($(this).attr('placeholder'));    
            }
        });
    });