Not only does IE6 not support the HTML5 Data Attribute feature, in fact virtually no current browser supports them! The only exception at the moment is Chrome.
You are perfectly at liberty to use data-geoff="geoff de geoff"
as an attribute, but only Chrome of the current browser versions will give you the .dataGeoff
property.
Fortunately, all current browsers - including IE6 - can reference unknown attributes using the standard DOM .getAttribute()
method, so .getAttribute("data-geoff")
will work everywhere.
In the very near future, new versions of Firefox and Safari will start to support the data attributes, but given that there's a perfectly good way of accessessing it that works in all browsers, then there's really no reason to be using the HTML5 method that will only work for some of your visitors.
You can see more about the current state of support for this feature at CanIUse.com.
Hope that helps.
data-geoff
isn't a valid JS identifier due to the "-" character. You'd need to usedataGeoff
in scripts. – Civismgeoff.dataGeoff
won't work, it'sundefined
. – Karlottageoff.dataGeoff
didn't work. It turned out (whatwg.org/specs/web-apps/current-work/multipage/…) that it should begeoff.dataset.geoff
, but aselement.dataset
is stillundefined
in modern browsers, that's neither supported. – Karlottafoo['invalid-name']
where one would want to dofoo.invalid-name
but couldn't. – Neveselem.attributes['data-geoff'].value
: jsfiddle.net/MEaVR/1 (It even works in IE8.) – NevesgetAttribute
, as it uses the DOM rather than HTML5 data attributes. Looks like a useful addition to his answer, though. – Civism