Created
November 4, 2013 09:50
-
-
Save pospi/7300392 to your computer and use it in GitHub Desktop.
Simple placeholder shim for IE. Functions slightly unlike browser placeholders in that the placeholder is removed immedately upon focus. To re-apply or activate elements added to the DOM post-render, simply call `.blur()` on them.
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
function initPlaceholderCompat() | |
{ | |
var test = document.createElement('input'), | |
placeholderSupport = 'placeholder' in test; | |
if (placeholderSupport) { | |
return; | |
} | |
$(document).on('focus', '[placeholder]', function() { | |
var input = $(this); | |
if (input.val() == input.attr('placeholder')) { | |
input.val(''); | |
input.removeClass('placeholder'); | |
} | |
}).on('blur', '[placeholder]', function() { | |
var input = $(this); | |
if (input.val() == '' || input.val() == input.attr('placeholder')) { | |
input.addClass('placeholder'); | |
input.val(input.attr('placeholder')); | |
} | |
}).on('submit', 'form', function() { | |
$(this).find('[placeholder]').each(function() { | |
var input = $(this); | |
if (input.val() == input.attr('placeholder')) { | |
input.val(''); | |
} | |
}) | |
}); | |
$('[placeholder]').blur(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment