1var element = document.querySelector('.element');
2var dataAttribute = element.getAttribute('data-name');
3// replace "data-name" with your data attribute name
4
5console.log(dataAttribute);
1for javascript :
2webappData.getAttribute('data-id');
3document.querySelector('#elementId').dataset.id = 'value';
4
5for jquery :
6$(element).attr('data-key', 'value');
1example <button data-keyname = "a'></button>
2
3let variable = element.dataset.keyname;
4or
5let varibale = element.['keyname'];
6or
7let variable = element.getAttribute('data-keyname');
1<!-- data-* attritubes can be used on any html element -->
2<div data-my-custom-data="true"></div>