Created
November 22, 2012 11:15
-
-
Save dave1010/4130621 to your computer and use it in GitHub Desktop.
HTML5 placeholder polyfill
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
if (!Modernizr.input.placeholder) { | |
// Old IE doesn't support the placeholder attribute on <input> | |
// TODO: placeholder colour and remove when submitting form | |
$(function() { | |
$('input[placeholder]').each(function() { | |
var ths = $(this), placeholder = ths.attr('placeholder'); | |
if (!ths.val()) { | |
ths.val(placeholder); | |
} | |
ths.focus(function() { | |
if (ths.val() === placeholder) { | |
ths.val(''); | |
} | |
}).blur(function() { | |
if (!ths.val()) { | |
ths.val(placeholder); | |
} | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment