# Hide submenus when I scroll page

**URL:** <https://forum.kirupa.com/t/hide-submenus-when-i-scroll-page/643023>\
**Category:** web dev\
**Created:** [May 30, 2020, 9:59am UTC](https://forum.kirupa.com/t/hide-submenus-when-i-scroll-page/643023 "2020-05-30T09:59:51Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [June 4, 2020, 8:20pm UTC](https://forum.kirupa.com/t/hide-submenus-when-i-scroll-page/643023/5 "2020-06-04T20:20:22Z")

</div>

One tiny addition is that, unlike getElementsByClassName, querySelectorAll returns a NodeList, and NodeList objects have a forEach built in. This means spreading to an array is not needed if you need forEach (note that other array methods like map are not built in, so you may want to spread then, or manually call map on the list via call()).

```javascript
addEventListener(
    'scroll',
    _ => document.querySelectorAll('.menu-submenu--show')
        .forEach(
            e => e.classList.remove('menu-submenu--show')
        )
)

```

getElementsByClassName return HTMLCollections which do not have a forEach. They are, like NodeLists, array-like, though, so you can ultimately use array methods on them (more on that in the array-likes tip of the day: [JavaScript Tips of the Day](http://forum.kirupa.com/t/javascript-tips-of-the-day/641803) ).

---

_[View the full topic](https://forum.kirupa.com/t/hide-submenus-when-i-scroll-page/643023)._
