Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda