js attribute code example
Example 1: set attribute javascript
Element.setAttribute(name, value);
Example 2: attribute in javascript
elem.hasAttribute(name)
elem.getAttribute(name)
elem.setAttribute(name, value)
elem.removeAttribute(name)
elem.attributes
Example 3: put new attribute on html tag using javascript
span.setAttribute("style", "width:110%;float:center;left-margin:-10px;top-margin:-10;");
Example 4: js setattribute
const link = document.querySelector('a');
console.log(link.getAttribute('href'));
link.setAttribute('href', 'https://yandex.ru');
link.innerText = 'The Next Link';
const mssg = document.querySelector('p');
console.log(mssg.getAttribute('class'));
mssg.setAttribute('class', 'success');
mssg.setAttribute('style', 'color: green;');