html dataset attribute code example

Example 1: html javascript find data attribute

//javascript get html data attribute



const btns=document.querySelectorAll('button[data-id]');
[...btns].forEach(btn => console.log(btn.getAttribute('data-id')))

Example 2: dataset js

for javascript : 
webappData.getAttribute('data-id');
document.querySelector('#elementId').dataset.id = 'value';

for jquery : 
$(element).attr('data-key', 'value');

Example 3: html data attribute


  	This tag contains a user-defined color attribute


This tag contains a data attribute with a link

Tags:

Misc Example