Last active
December 23, 2015 11:19
-
-
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.
This file contains hidden or 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
/** 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')); | |
} | |
}); | |
} | |
}); |
This file contains hidden or 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
<!-- 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