Are HTML 5 data- attribute and jQuery data same thing?

痞子三分冷 提交于 2019-12-12 04:44:18

问题


In HTML 5 its possible to set arbitrary 'data-' attributes to elements like

<div data-blah="blah">

The jQuery framework has methods to do similar things (.data() etc). My question is do the jQuery methods just manipulate and read these html5 data attributes, or they are referring to different jQuery-type data-attributes?


回答1:


No, totally different things. jQuery's .data() existed even before HTML5.

See: http://api.jquery.com/data/ for details.

To get HTML5 data- attribute value from html tag, try:

jQuery('selector here').attr('data-blah');


来源:https://stackoverflow.com/questions/22113046/are-html-5-data-attribute-and-jquery-data-same-thing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!