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

68
Visualizações
Querying complex html document

I'm trying to query a complex web app for some data...

A very simplified example is the below

<section class="Test newTest testTest active">
  <div>
   </div>
   <a class="classLink1 classlink2 classlink3" data-render="test">Link</a>
   </div>
  </div>
</section>

<section class="Test newTest testTest">
  <div>
   </div>
   <a class="classLink1 classlink2 classlink3" data-render="test">Link</a>
   </div>
  </div>
</section>

Problem

  • There are a few <a> tags with very similasr class names and some dataset with unique values which I don't want to query
  • I'm trying to only target the <a> tag where the parent <section> has an .active class. But it may not be the immediate parent if that makes sense

I am trying something like this

document.querySelectorAll('section.Test.newTest.testTest.active a.classLink1.classlink2.classlink3 [data-render="test"]')

But it seems to return an empty nodelist.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You must not have the space between classlink3 and [data-render="test"], as the elements you are searching for have both classes and attribute, and aren't nested inside the "classes" element.

The right selector should be

'section.Test.newTest.testTest.active a.classLink1.classlink2.classlink3[data-render="test"]'

Which will select the following

enter image description here

Instead of

enter image description here

about 4 years ago · Santiago Trujillo Relatório
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