I'm storing some custom data in HTML5 data attribute for Jquery processing. will the custom data attribute available in Older browsers?
The data-* attribute is used to store custom data private to the page or application. The data-* attribute gives us the ability to embed custom data attributes on all HTML elements.
HTML <data> Tag.
HTML <select> data-* Attribute. A data-* attribute on a <select> tag attaches additional data to the dropdown control. To create a custom attribute, replace * with a lowercase string, such as data-id , data-status , or data-location .
To retrieve a data-* attribute value as an unconverted string, use the attr() method. Since jQuery 1.6, dashes in data-* attribute names have been processed in alignment with the HTML dataset API. $( "div" ).
The HTML5 datalist
property is not available in older browsers (it can be polyfilled easily enough though). You can always use the standard getAttribute
method instead of course, and data-xxx
attributes on HTML elements are accepted by all browsers (as long as you're in HTML mode and not xHTML where they're invalid)
But your question seems to be more specifically about jQuery than HTML5, and for that, the answer is Yes -- the jQuery .data()
method is available in all browsers supported by jQuery.
The attribute itself will work in all browsers. It's just an attribute after all. This would "work" in the sense that the attribute will exist in the DOM:
<div random-attribute="hello"></div> <!-- invalid, but "works" -->
<div data-random="hello"></div> <!-- valid (in browsers with HTML5 support) -->
The native dataset
property of elements will not work in older browsers, but getAttribute
will:
var random = document.getElementById("x").dataset.random;
// or
var random = document.getElementById("x").getAttribute("data-random");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With