Skip to content

Instantly share code, notes, and snippets.

@nobuf
Created August 21, 2012 22:15
Show Gist options
  • Save nobuf/3419910 to your computer and use it in GitHub Desktop.
Save nobuf/3419910 to your computer and use it in GitHub Desktop.
Supporting placeholder on IE9 with AngularJS + jQuery
angular.module('test', [])
.directive('placeholder', function($timeout){
if (!$.browser.msie || $.browser.version >= 10) {
return {};
}
return {
link: function(scope, elm, attrs){
if (attrs.type === 'password') {
return;
}
$timeout(function(){
elm.val(attrs.placeholder).focus(function(){
if ($(this).val() == $(this).attr('placeholder')) {
$(this).val('');
}
}).blur(function(){
if ($(this).val() == '') {
$(this).val($(this).attr('placeholder'));
}
});
});
}
}
});
@blowsie
Copy link

blowsie commented Nov 4, 2013

you should consider using this statement for placeholder detection rather than browser sniffing. if ('placeholder' in $('<input type="text">')[0] == false)

Also you gist will leak memonry as you are not cleaning up the events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment