Skip to content

Instantly share code, notes, and snippets.

@aronbudinszky
Last active December 23, 2015 11:19
Show Gist options
  • Save aronbudinszky/6627995 to your computer and use it in GitHub Desktop.
Save aronbudinszky/6627995 to your computer and use it in GitHub Desktop.
A very short polyfill for IE placeholders. It's not meant to be perfect, but it is tiny and takes care of the most important use case for placeholders: to give additional info about how to fill it out. Requires jquery.
/** POLYFILL FOR IE PLACEHOLDER **/
$(document).ready(function(){
if(!('placeholder' in document.createElement('input'))){
$('input[placeholder]').each(function(){
if(this.value == ''){
var $el = $(this);
$el.bind('click', function(ev){ $(ev.target).unbind('click'); ev.target.value = ''; });
$el.val($el.attr('placeholder'));
}
});
}
});
<!-- Use placeholders as you normally would -->
<input type="text" name="example" placeholder="This is just an example">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment