Will HTML 5 data attribute support in old browsers?

前端 未结 4 2275
夕颜
夕颜 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: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:

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

提交回复
热议问题