{{ APIRef() }}
Used by the {{ htmlattrxref("dataset") }} HTML attribute to represent data for custom attributes added to elements.
Method overview
DOMString getDataAttr(in DOMString prop); {{ noscript_inline() }} |
boolean hasDataAttr(in DOMString prop); {{ notxpcom_inline() }} |
void removeDataAttr(in DOMString prop); {{ notxpcom_inline() }} |
void removeProp(in nsIAtom attr); {{ notxpcom_inline() }} |
void setDataAttr(in DOMString prop, in DOMString value); {{ noscript_inline() }} |
Methods
{{ method_noscript("getDataAttr") }}
DOMString getDataAttr( in DOMString prop );
Parameters
-
prop
- The property for which to retrieve the value.
Return value
The value for the specified property name.
{{ method_notxpcom("hasDataAttr") }}
boolean hasDataAttr( in DOMString prop );
Parameters
-
prop
- The property for which to check for the existence of a value.
Return value
true
if the property exists; otherwise false
.
{{ method_notxpcom("removeDataAttr") }}
void removeDataAttr( in DOMString prop );
Parameters
-
prop
- The property to remove from the data set.
{{ method_notxpcom("removeProp") }}
Removes the property from the dataset object. Used to update the dataset object when data-* attribute has been removed from the element.
void removeProp( in nsIAtom attr );
Parameters
-
attr
- The property to remove from the dataset.
{{ method_noscript("setDataAttr") }}
Sets the value of the specified property.
void setDataAttr( in DOMString prop, in DOMString value );
Parameters
-
prop
- The property whose value is to be set.
-
value
- The property's new value.
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{ CompatUnknown() }} | {{ CompatGeckoDesktop("6.0") }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
See also
- {{ domxref("element.dataset") }}
- {{ htmlattrxref("dataset") }}