placeholderSupport = ("placeholder" in document.createElement("input"));
if(!placeholderSupport){
//This browser does not support the placeholder attribute
//use javascript instead
}
outputs true or false
HTML5 introduced the placeholder attribute which saves us so much time/headache when we just want some placeholder text in a text input that disappears on focus and reappears on blur (if there's no user input).
Unfortunately not all browsers support it. Therefore, we can use progressive enhancement. Use the HTML5 for those that support it (Chrome, Safari, FF 3.7+, etc.) and fall back to javascript techniques for those that don't.
Want to learn great syntax? Have great syntax to share? Syntactic Sugr is a community of expert developers sharing syntactic sugar and other powerful snippets.
Comments
No comments have been posted