Skip to content

Instantly share code, notes, and snippets.

@gabssnake
Created September 2, 2014 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabssnake/a7fdf4a4ee23a37d0d3f to your computer and use it in GitHub Desktop.
Save gabssnake/a7fdf4a4ee23a37d0d3f to your computer and use it in GitHub Desktop.
placeholder polyfill
// simple placeholder polyfill (requires jQuery)
// http://snippetrepo.com/snippets/html5-placeholder-on-ie8-input-fields
(function($, document){
var test = document.createElement('input');
var polyfill = function () {
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
}
if ('placeholder' in test) polyfill();
})(jQuery, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment