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

117
Vistas
nth child selector causing javascript to get wrong display property

Trying to build a website that kind of lets you read chapters from a book. However I'm trying to implement a show more button so that the screen won't get cluttered.

I'm doing this by making the display:none with the css nth child selector and then using javascript to get all the elements with a display none and making them visible again.

However I noticed that when I use the nth child selector to make some elements hidden, javascript now says they all have a display of block.

{% for chapter in chapters %}
         <div class="col-md-2 col-sm-12" id="chapter-list">
                <div class="chapter-link-container">
                    <a href="{% url 'chapter-detail' chapter.manga.slug chapter.slug %}">Chapter {{chapter.number}}</a>
                </div>
         </div>
{% endfor %}
#chapter-list:nth-child(2){
    display: none;
}
let listItems = document.getElementsByClassName('chapter-link-container')
for(i=0; i< listItems.length; i++){
    const style = getComputedStyle(listItems[i])
    console.log(style.display)
}

when log this it prints out block 4 times

enter image description here

However we know that the second child has a display none I ran this code again but only changed nth child to div just to make sure.

#chapter-list div{
    display: none;
}

and sure enough every display was none

enter image description here

about 4 years ago · Juan Pablo Isaza
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