R
RobG
HTML5 introduces the placeholder attribute[1] for elements that allow
user input. This replaces the common script solution that uses focus
and blur events to put a hint in empty inputs and textarea elements.
To detect support for placeholder (and aovid attaching unnecessary
listeners), I've come across the following code:
var placeholderSupported = (function() {
var el = document.createElement('input');
el.type = 'text';
return 'placeholder' in el;
}());
While it "works" in all the browsers I've tested (IE (no support),
Safari (desktop and mobile), Firefox (with and witout support), Opera
(with and without support) and Chrome), it doesn't seem reasonable to
me to expect DOM elements to be given a property for every default
attribute that they support. Am I wrong about that? Is it reasonable
to expect that for an element created by createElement, if <property>
in <element> returns true that the browser supports that HTML
attribute?
1. <URL: http://dev.w3.org/html5/spec/Overview.html#the-placeholder-attribute
user input. This replaces the common script solution that uses focus
and blur events to put a hint in empty inputs and textarea elements.
To detect support for placeholder (and aovid attaching unnecessary
listeners), I've come across the following code:
var placeholderSupported = (function() {
var el = document.createElement('input');
el.type = 'text';
return 'placeholder' in el;
}());
While it "works" in all the browsers I've tested (IE (no support),
Safari (desktop and mobile), Firefox (with and witout support), Opera
(with and without support) and Chrome), it doesn't seem reasonable to
me to expect DOM elements to be given a property for every default
attribute that they support. Am I wrong about that? Is it reasonable
to expect that for an element created by createElement, if <property>
in <element> returns true that the browser supports that HTML
attribute?
1. <URL: http://dev.w3.org/html5/spec/Overview.html#the-placeholder-attribute