1var element = document.querySelector('.element');
2var dataAttribute = element.getAttribute('data-name');
3// replace "data-name" with your data attribute name
4
5console.log(dataAttribute);
1//javascript get html data attribute
2<button data-id="1" >Click</button>
3<button data-id="2" >Click</button>
4<button data-id="3" >Click</button>
5const btns=document.querySelectorAll('button[data-id]');
6[...btns].forEach(btn => console.log(btn.getAttribute('data-id')))
1const article = document.querySelector('#electric-cars');
2
3article.dataset.columns // "3"
4article.dataset.indexNumber // "12314"
5article.dataset.parent // "cars"