bleedCoder
bleedCoder

Reputation: 369

Will HTML 5 data attribute support in old browsers?

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

Upvotes: 14

Views: 10475

Answers (4)

Antonio Vasilev
Antonio Vasilev

Reputation: 2965

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?

Upvotes: 0

Spudley
Spudley

Reputation: 168685

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.

Upvotes: 21

James Allardice
James Allardice

Reputation: 165971

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");

Upvotes: 10

Daniele
Daniele

Reputation: 1938

check this site for browser compatibilities in HTML5

html5test.com

Upvotes: 1

Related Questions