Ask coding questions

← Back to all posts
getElementsbyClass
AstrumDeorum (10)

I know this exists, however for some reason I can't seem to be able to utilize it in replit. Does anyone know an alternative I could use instead, or a way to use it?

Answered by EpicGamer007 (1606) [earned 5 cycles]
View Answer
Comments
hotnewtop
EpicGamer007 (1606)

document.getElementsByClassName('class-name'), its not document.getElementsByClass. its document.getElementsByClassName

ch1ck3n (1574)

document.querySelector(".class-name") you need the dot in front for it to work. you can also put a # in front to make it select from ID. or any other css selectors.

https://www.w3schools.com/cssref/css_selectors.asp