Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!