I've got some code:
<a data-id="pagetwo" href="#">PAGE 2</a>
In the above case:
e.target.dataset.id is pagetwo
I don't understand
<a id="myelement" data-flora="plants"></a>
<div id="somediv" data-fauna="animals"></div>
Might I suggest not using data-id? It can be reasonably easily confused with an element's id.
Further reading: http://html5doctor.com/html5-custom-data-attributes/
The dataset object is cross-browser supported, however, it's part of the HTML5 specification that is not yet finalized and thus, only the newest browsers will support the dataset object.
thanks for the. a bit more clued up now
that article is great - understand a lot better now
+ i understand that the use of 'id' is wrong (the original code was someone elses - who actually should have known better)
dataset - can i assume this is widely implemented in all browsers?
at the end of the article, the author mentions not to use because no browsers had implemented - but that was in 2010?
Nope, not widely supported because legacy browsers are still in use. It's not supported in IE<10 (and I'm not even sure about 10). Nor is it implemented in Firefox 3.6 (the most popular legacy version of Firefox).
It's not widely implemented and you can't depend on it as a cross-browser solution.
hmm... i was using for mobile app/website development
does that change anything?
It depends on what mobile, and on what type of layout engine / browser. Usually the mobiles' browsers do support most of the HTML5 features, but you have to verify that for each type of layout engines: Webkit (Safari, Chrome), Gecko(Moz), Presto (Opera), etc... and their versions.
Originally Posted by OM2
guys: thanks for that. i've been developing in sencha. works on my desktop chrome browser. i'm now happy that i hadn't developed further - only to find last minute that i've got some damn unknown problem - that would be hard to track down
Originally Posted by Kor
hmm... i just talked to someone else, they said dataset was quite widely available and gave me this link:
Note: All browsers can already use data-* attributes and access them using getAttribute. "Supported" refers to accessing the values using the dataset property.
Looking closely at the link you just provided I can tell you that the dataset object is available in the following browsers:
iOS Safari 5+
Opera Mobile 12+
Android Browser 3+
In all other browsers, you must use the getAttribute() method to access the data- attribute on the HTML element.
EDIT: While that does appear to be pretty widely available, the chart shows 0% support in any IE browser, modern or legacy to date.
Agree. Yet somehow I would opt rather for getAttributeNode() method, as it deals with the nodes directly, even if, as far as I could see, it is seldom used.
Originally Posted by aj_nsc
The problem is that getAttribute() searches for native HTML attributes, while getAttributeNode() acts like an XML method, and it will refer any kind of attributes, native or custom.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)