I want to use forEach
method with getElementsByClassName
in Java script,i dont want to use querySelectorAll
or forloops.
I want it to be pure Javascript without any Jquery
I tried this….
const allElements = document.getElementsByClassName('class')
allElements.forEach(element =>{
console.log(element)
)})
I tried to use this but it throws an error
Uncaught TypeError: Cannot read properties of undefined (reading ‘forEach’)
I also tried to use
const allElements = document.querySelectorAll('.class')
allElements.forEach(element =>{
console.log(element)
)})
But it also throws the same error