Czulu
Czulu

Reputation: 85

Are HTML data attributes and jQuery's .data() same thing?

In HTML it's possible to set custom '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?

Upvotes: 0

Views: 133

Answers (1)

Aoi Karasu
Aoi Karasu

Reputation: 3825

No, totally different things. jQuery's .data() existed even before W3C added these to HTML version 5.

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

To get an HTML data- attribute value from an HTML tag, try:

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

Upvotes: 1

Related Questions