Created
May 25, 2011 15:47
-
-
Save jordanharper/991217 to your computer and use it in GitHub Desktop.
Activate <input> placeholder attributes for non webkit browsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('input[placeholder]').each(function(){ | |
$(this).focus(function(){ | |
if ($(this).val()==$(this).attr('placeholder')) $(this).val(''); | |
}).blur(function(){ | |
if ($(this).val()=='') $(this).val($(this).attr('placeholder')); | |
}); | |
}); | |
Or, using modernizer: | |
if(!Modernizr.input.placeholder){ | |
$("input").each(function(){ | |
if($(this).val()=="" && $(this).attr("placeholder")!=""){ | |
$(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")); | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment