HTML5 Placeholder in IE7 and IE8 fix

You can now use the HTML5 placeholder attribute in IE7 & IE8 – just use this code below. Origionally found at: dipaksblogonline

//Assign to those input elements that have 'placeholder' attribute
$('input[placeholder]').each(function(){  
    var input = $(this);        
    $(input).val(input.attr('placeholder'));

    $(input).focus(function(){
        if (input.val() == input.attr('placeholder')) {
           input.val('');
        }
    });

    $(input).blur(function(){
       if (input.val() == '' || input.val() == input.attr('placeholder')) {
           input.val(input.attr('placeholder'));
       }
    });
});
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: