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, 1270 Views

Thanks everyone! Wrapping my code in `DOMContentLoaded` fixed it. Didn’t realize the script was running too early.

Also, tried `querySelectorAll` like some of you suggested, and it’s way cleaner with `forEach`.

One last thing—if I dynamically add more elements later, should I re-run the selector or is there a smarter way?

Messages In This Thread



Users browsing this thread: 1 Guest(s)