How do I use get element by class in JavaScript? or What's the best way to get element by class for d

14 Replies, 1273 Views

Dude, get element by class is kinda outdated tbh. `querySelectorAll` is way more flexible—you can use it like `document.querySelectorAll('.my-class')` and it returns a NodeList that supports `forEach`.

But if you’re stuck with get element by class, remember it’s case-sensitive and won’t work if the elements are hidden or not in the DOM yet.

Check your dev tools to confirm the elements exist when your code runs!

Messages In This Thread



Users browsing this thread: 1 Guest(s)