Not public class?

Hello.

I can not understand why is not working the closeMenu function. That is why classes are not removed.

Most likely I'm just stupid and can't understand something obvious, but nevertheless, I didn't expect all this.

https://jsfiddle.net/h4wc1qfa/

<button class="btn">Click me</button>
<div class="menu">
123
</div>


.menu{
 display: none;
}
.responsive{
 display: block;
}


const resBtn = document.querySelector('.btn'),
 resMenu = document.querySelector('.menu');



const openMenu = e=>{
if(e.target){
e.preventDefault();
}
 if(resBtn.classList.contains('exprended') === true){
closeMenu();
}
resBtn.classList.add('exprended');
resMenu.classList.add('responsive');
};

const closeMenu = ()=>{
resBtn.classList.remove('exprended');
resMenu.classList.remove('responsive');
};




resBtn.addEventListener('click', openMenu);


Please tell me, what's the problem?
April 19th 20 at 12:31
1 answer
April 19th 20 at 12:33
Solution
We need to stop the execution of the function using return; to once again not to add classes.
or remove all add in an else - ross commented on April 19th 20 at 12:36
@Dorian42 Thank you, totally forgot about it - derrick.Kunde commented on April 19th 20 at 12:39

Find more questions by tags JavaScript