0

I am creating elements in a for loop and would like to add event listener to all of them, but not sure how to do that?

for (let i = numberOfPages; i >  0; i--){
    var link = navLinksTemplate({ pageNumber: i });
    previous.insertAdjacentHTML('afterend', link);
  }

I need to do it with vanilla js.

Leff
  • 1,744
  • 11
  • 63
  • 133
  • What about giving them a specific class and have the event listener on that class with the `querySelector` ([*see this*](http://stackoverflow.com/questions/14258787/add-event-listener-on-elements-created-dynamically)). – Spencer Wieczorek Apr 11 '17 at 16:22
  • Scroll down to the 5th answer in the linked question to see how to do it without jQuery. – Barmar Apr 11 '17 at 16:23
  • I don't want to use jQuery, I need to do it with vanilla javascript – Leff Apr 11 '17 at 16:24

0 Answers0