0

Serious noob question. I'm using node.js and handlebars. I'm using handlebar's {{#each}} to generate a .div for each post in my database. Problem is, when I use below document.getElement in my client-side main.js file it's only getting the first post. Please help me to get it working regardless of how many posts there are. Thank you!

document.getElementById("dropdown").classList.toggle("show");
document.getElementById('grabMe').classList.toggle("rotate");
F. Fifi
  • 3
  • 2
  • IDs must be unique to the document. – Heretic Monkey Feb 21 '19 at 22:29
  • Possible duplicate of [getElementById returning value only for first element](https://stackoverflow.com/questions/24123707/getelementbyid-returning-value-only-for-first-element) – Heretic Monkey Feb 21 '19 at 22:29
  • Yep, as others have mentioned, IDs are meant to be assigned to a single element. Instead of creating multiple elements with the same ID, consider using a `class` instead. So if you output `` within your `{{#each}}` loop, then running `document.querySelectorAll('.dropdown')` will return a NodeList that contains all your dropdown divs. – romellem Feb 25 '19 at 17:04

0 Answers0