When I use this code to add & remove the style , Part ( else ) only works and sets (display) to block, But it will not return the class if clicked again. what's wrong?
var navDropDown = document.querySelectorAll('.menu-item-has-children > a');
for (let i = 0; i < navDropDown.length; i++) {
navDropDown[i].addEventListener('click', (e) => {
if (navDropDown[i].nextElementSibling.style.display = 'none') {
this.nextElementSibling.style.display = 'block';
} else {
this.nextElementSibling.style.display = 'none';
}
})
}