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

172
Vistas
How to make always only 3 elements appear even after 1 of them is appended?

I need only max 3 elements to appear on the screen at all times and if one of them is removed, then the next in line takes its place and so on till the are no elements.

Here is the code snippet:

<div class="mob-keys-container" id="mob-keys-container">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_1_mob" src="./images/5.1.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_2_mob" src="./images/5.2.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_3_mob" src="./images/5.3.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_4_mob" src="./images/5.4.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_5_mob" src="./images/5.5.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_6_mob" src="./images/5.6.png" alt="key">

 </div>

And here is the best code that kinda works:

$('.info-mob').on('click', () => {
        $('#mob-keys-container').toggle();
        $('#mob-keys-container').children().slice(0, 3).show();
    });

.info-mob opens a tab that contains all the elements and while it's open there should be max 3 elements. Everything works fine if I close and open up again that tab but I need it to be more dynamic and always be max 3 elements even if I append one with different function.

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

0

I think this will solve your issue with help of CSS

#mob-keys-container *{
  display:none;
}

#mob-keys-container *:nth-child(-n+3){
  display:block;
}
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