Created
June 28, 2012 00:40
-
-
Save llkats/3007909 to your computer and use it in GitHub Desktop.
emulate placeholders in IE9 and other dumb browsers
This file contains 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
// test to see if the browser supports native html5 placeholders | |
jQuery.support.placeholder = (function(){ | |
var i = document.createElement('input'); | |
return 'placeholder' in i; | |
})(); | |
// if the browser doesn't support placeholders (IE9!!!!!!), do them manually | |
if (!$.support.placeholder) { | |
$("input").each(function(){ | |
var current = $(this); | |
if (current.val() === "" && current.attr("placeholder") !== "") { | |
current.val(current.attr("placeholder")); | |
current.focus(function() { | |
if(current.val() === $(this).attr("placeholder")) { | |
$(this).val(""); | |
} | |
}); | |
$(this).blur(function() { | |
if($(this).val() === "") { | |
$(this).val($(this).attr("placeholder")); | |
} | |
}); | |
} | |
}); | |
} | |
/* | |
* via | |
* http://stackoverflow.com/questions/8263891/simple-way-to-check-if-placeholder-is-supported | |
* http://kamikazemusic.com/quick-tips/jquery-html5-placeholder-fix/ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment