How to fix "Uncaught TypeError: learnmore.forEach is not a function"?

Trying to write a function to call the modal window.
html
<div class="description-btn"> Learn more</div>


JS
let learnmore = document.getElementsByClassName('.discription-btn');

learnmore.forEach(function(el){
 el.addEventListener('click', function(){
 overlay.style.display = 'block';
this.classList.add('more-splash');
 document.body.style.overflow = 'hidden'; // block scrolling body with an open MO 
});
 });


And of course the output (to click) have the error "Uncaught TypeError: learnmore.forEach is not a function". Why? How to do it properly?
April 3rd 20 at 18:34
3 answers
April 3rd 20 at 18:36
Solution
Because the function returns not an array, but forEach is a method of the prototype array.

Solution:
  • To substitute for querySelectorAll, getElementsByClassName, then you will get an object of type NodeList, the prototype of which is fofEach.

  • To turn your fairway object to an array using the spread operator, or method Array.from.

  • To delegate the event.

  • To sort through for.
not working!(( - rosalyn_Casper commented on April 3rd 20 at 18:39
more precisely, the error is gone) the window doesn't appear) - rosalyn_Casper commented on April 3rd 20 at 18:42
April 3rd 20 at 18:38
Solution
April 3rd 20 at 18:40
let learnmore = document.getElementsByClassName('discription-btn');

Find more questions by tags JavaScript