Will HTML 5 data attribute support in old browsers?

前端 未结 4 2271
夕颜
夕颜 2021-02-19 07:55

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

相关标签:
4条回答
  • 2021-02-19 08:14

    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?

    0 讨论(0)
  • 2021-02-19 08:18

    check this site for browser compatibilities in HTML5

    html5test.com

    0 讨论(0)
  • 2021-02-19 08:24

    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.

    0 讨论(0)
  • 2021-02-19 08:28

    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");
    
    0 讨论(0)
提交回复
热议问题