function collapseMenu() { let menu = document.querySelector(".menu"); let menuChildren = menu.querySelectorAll('li'); let i = menuChildren.length - 1; let other = document.createElement("li"); other.setAttribute("onclick", "submenu(this)"); other.id = 'other'; other.innerHTML = 'More'; let submenu = document.createElement("ul"); submenu.classList.add('submenu', 'hidden'); other.appendChild(submenu); if (menu.offsetWidth >= window.innerWidth) { let drop; if (!menu.contains(document.getElementById('other'))) { menu.appendChild(other); } while (menu.offsetWidth >= window.innerWidth) { drop = menu.removeChild(menuChildren[i]); submenu.prepend(drop); i--; } } else { //On increase window } } collapseMenu(); window.addEventListener('resize', collapseMenu);por favor ayuda, gracias