Home  »  CodeProgrammingSnippetsTechnology   »   How to get HTML Element Data Attribute in jQuery

How to get HTML Element Data Attribute in jQuery

Posted: August 3, 2022 | by Site Host

Take this data attribute as an example.

<div id="element" class="element" data-name="Mary"></div>

Get the data attribute.

//get data-id using jQuery
var dataName = $('#element').data('data-name');

console.log("dataName"); // Mary

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

See also  How to Make Links Unclickable in CSS