Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
how to remove nav item on window resize?

I want target to prepent in more dropdown when screen size is below 1190px & remove target from dropdown when screen size is above 1190px

This is the outcome i want

I can make target disappear easily but target to appear in dropdown part is tricky. I've used window.onresize & window.onload with below condition

if (window.innerWidth < 1190 && window.innerWidth > 1188) { var dt = document.createElement("dt"); dt.innerHTML = 'Target'; dt.className = '.target' dl.prepend(dt); } if (window.innerWidth > 1189 && window.innerWidth < 1191) { console.log('done') dt?.remove() }

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If you're okay with using CSS for this, then a really easy way to do it would be to use media queries.

@media only screen and (min-width: 1189px) and (max-width: 1191px) {
  .target {
    display: none;
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Maybe you can create static targets and manage who is gonna be hidden using classes:

jsfiddle

  <nav>
    <ul>     
      <li>
        Home
      </li>
      <li>
        Item
      </li>
      <li id="target-main">Target</li>
      <li class="nav-more-container">More
        <ul class="nav-more-list">
         <li id="target-more">Target</li>
          <li>Item</li>
          <li>Item 2</li>
        </ul>
      </li>
    </ul>
  </nav>

.hidden {
  display: none;
}

window.addEventListener("resize", () => {
 const {
  innerWidth
 } = window;

 const targetMain = document.getElementById("target-main");
 const targetMore = document.getElementById("target-more");

 if (innerWidth < 1190) {
   targetMain.setAttribute("class", "hidden");
   targetMore.setAttribute("class", "");
 } else {
   targetMain.setAttribute("class", "");
   targetMore.setAttribute("class", "hidden");
 }
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda