I have a menu with links and i have them toggle their hr's opacity to 1 when i click on each link, of course making all other links (hrs) on the menu back to the original opacity of 0 which they previously had (Classic menu UX).
The problem is to achieve this i had to use 2 nested for loops using JS. From what i learned about Big O notation, that isn't very effiecient, especially that with jquery all this code is done in a single line. My question is how can i improve the efficiency of this code with Vanilla JS only?
HTML
<div className="menu">
<h6>Home<hr/></h6>
<h6>Movies<hr/></h6>
<h6>TV Shows<hr/></h6>
<h6>Documentaries<hr/></h6>
<h6>Favorites<hr/></h6>
<h6>Collection<hr/></h6>
</div>
JS
const menulink = document.querySelectorAll('.menu h6')
for(let item of menulink) {
item.onclick = () => {
for(let i=0;i<menulink.length;i++) {
menulink[i].querySelector('hr').style.opacity = '0'
}
item.querySelector('hr').style.opacity = '1'
}
}