14

I'm storing some custom data in HTML5 data attribute for Jquery processing. will the custom data attribute available in Older browsers?

bleedCoder
  • 369
  • 2
  • 7
  • 17
  • take a look at this http://stackoverflow.com/questions/2815128/what-browsers-are-compatible-with-html5 – Christian Phillips Aug 08 '13 at 09:36
  • 1
    possible duplicate of [Do HTML5 custom data attributes “work” in IE 6?](http://stackoverflow.com/questions/2412947/do-html5-custom-data-attributes-work-in-ie-6) – whostolemyhat Aug 08 '13 at 09:46

4 Answers4

21

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.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • @bleedCoder - you should use the green tick icon next to the most helpful answer to mark that answer as "accepted". This will reward the person who wrote the answer, and also help others who are looking for the same issue in the future to find the right answer. – Spudley Aug 08 '13 at 12:28
10

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");
James Allardice
  • 164,175
  • 21
  • 332
  • 312
1

check this site for browser compatibilities in HTML5

html5test.com

Daniele
  • 1,938
  • 16
  • 24
0

Anything that supports HTML will be able to access a HTML data attribute. So processing it client side via JQUERY should be absolutely fine.

In fact, i recently had to do this for a project at work and it worked a treat all the way down to ie7.

If you want to use the HTML data attributes for styling via CSS, then you would need browsers that support CSS3 selectos. Which is anything below IE9 and some older versions of firefox.

This might be of interest to you:

Do HTML5 custom data attributes “work” in IE 6?

Community
  • 1
  • 1
Antonio Vasilev
  • 2,845
  • 2
  • 14
  • 17