Created
April 9, 2013 17:13
-
-
Save nessthehero/5347505 to your computer and use it in GitHub Desktop.
Simple 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
// Requires Modernizr | |
if (!Modernizr.input.placeholder) { ph(); } | |
function ph() { | |
$("input[placeholder]:not(.ph)").each(function () { | |
var place = $(this).attr('placeholder'); | |
$(this).attr('value', place); | |
$(this).bind('focus', function () { | |
if ($.trim($(this).attr('value')) == place) { | |
$(this).attr('value', ""); | |
} | |
}); | |
$(this).bind('blur', function () { | |
if ($.trim($(this).attr('value')) == '') { | |
$(this).attr('value', place); | |
} | |
}); | |
$(this).addClass('ph'); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment