I have three elements named one, two, and three, declared as seen below:
<div id =container>
<div id 'one' class="element one"></div>
<div id 'two' class="element two"></div>
<div id 'three' class="element three"></div>
</div>
With the initial statements:
const container = document.querySelector('#container');
const elements = document.querySelectorAll(".element");
I want to use console.log to print out the class of each element. So far I have managed to get their IDs using this code:
elements.forEach((elem, i) => {
console.log(elem.id);
});
How can I modify my code to display the class name of each element as 'one', 'two', 'three'?
const container = document.querySelector('#container');
const elements = document.querySelectorAll(".element");
elements.forEach((elem, i) => {
console.log(elem.id);
});
<div id=container>
<div id 'one' class="element one"></div>
<div id 'two' class="element two"></div>
<div id 'three' class="element three"></div>
</div>