Answers for "js custom attribute"

12

js get data attribute

var element = document.querySelector('.element');
var dataAttribute = element.getAttribute('data-name');
// replace "data-name" with your data attribute name

console.log(dataAttribute);
Posted by: Guest on February-03-2020
0

js get custom attribute

document.getElementById("divId").getAttribute("attributeId");
Posted by: Guest on June-15-2021
5

get data attribute javascript

// <div id="element" data-name="john"></div>

const el = document.querySelector('#element')
el.dataset.name // 'john'
Posted by: Guest on November-02-2020

Code answers related to "js custom attribute"

Code answers related to "Javascript"

Browse Popular Code Answers by Language