1element.setAttribute(<name>, <value>);
2// ex
3var aElement = document.querySelector("a");
4aElement.setAttribute("href", "https://isitchristmas.com/");
5// same as <a href="https://isitchristmas.com/"></a>
1element.setAttribute(name, value);
2
3
4var d = document.getElementById("d1");
5d.setAttribute("align", "center");
1element.setAttribute(name, value);
2element.setAttribute("style", "background-color: red;");
1const link = document.querySelector('a');
2
3console.log(link.getAttribute('href'));
4link.setAttribute('href', 'https://yandex.ru');
5link.innerText = 'The Next Link';
6
7const mssg = document.querySelector('p');
8
9console.log(mssg.getAttribute('class'));
10
11mssg.setAttribute('class', 'success');
12mssg.setAttribute('style', 'color: green;');