HTML:
<body>
<p>Colors</p>
<ul>
<li>Red</li>
<li>Green</li>
<li>Bleu</li>
</ul>
</body>
CSS:
body {
background-color: #8fbc8f;
font-family: Arial, sans-serif;
font-size: 1em;
}
.first { color: red; }
.second { color: green; }
.third { color: blue; }
I need to use the .setAttribute() so that 'Red' gets the .first from CSS, 'Green' gets the .second and 'Blue' gets the .third. I've tried many things but i don't know which name and value I have to use so my code is correct.
Below is my script at the moment which doesn't seem to work. Can somebody tell me how I can do this?
function Colors() {
let color = document.getElementsByTagName("li");
color[0].setAttribute("demo.css","first");
color[1].setAttribute("demo.css","second");
color[2].setAttribute("demo.css","third")
}