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

130
Views
How to use querySelectorAll only for elements that have a specific child element?
    <table>
      <tr>
        <th>Column name</th>
        <th>Column name</th>
      </tr>
      <tr>
        <td>Column value</td>
        <td>Column value</td>
      <tr>
    </table>
    <table>
      <tr>
        <th>Column name</th>
        <th>Column name</th>
      </tr>
      <tr>
        <td>Column value</td>
        <td>Column value</td>
      <tr>
    </table>

I'd like to process all tr that contain a td, but can only find contain queries for attributes and content; not elements. Is the latter possible with a single query?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Not directly, but you can use filter to get the appropriate rows

const rowsWithTd = [...document.querySelectorAll("table tr")].filter( x => x.querySelector("td"))
console.log(rowsWithTd.map(x => x.outerHTML))
<table>
  <tr>
    <th>Column name</th>
  </tr>
  <tr>
    <td>Column value</td>
  <tr>
</table>
<table>
  <tr>
    <th>Column name</th>
  </tr>
  <tr>
    <td>Column value</td>
  <tr>
</table>

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