setattribute data javascript code example
Example 1: how to set data attribute in js using setattribute
// setting data-foovar el = document.querySelector('div');el.setAttribute('data-foo', 'Hello World!');
Example 2: setAttribute()
element.setAttribute(name, value);
element.setAttribute("style", "background-color: red;");