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

88
Views
How can I make the function querySelectorAll select a class AND a src at the same time?

I've created the following code:

const circle = document.querySelectorAll('[src = "https://cdn-icons-png.flaticon.com/512/734/734544.png"]')
const classTwo = document.querySelectorAll('.one')

const circleANDClassTwo = document.querySelectorAll('.one [src = "https://cdn-icons-png.flaticon.com/512/734/734544.png"]')

//console.log(circle)
//console.log(classTwo)
console.log(circleANDClassTwo)
<img id="1" src="https://i.imgur.com/ZcGeIVz.png" class="one" style="width:50px;height:50px">
<img id="2" src="https://i.imgur.com/ZcGeIVz.png" class="one" style="width:50px;height:50px">
<img id="3" src="https://i.imgur.com/ZcGeIVz.png" class="one" style="width:50px;height:50px">
<img id="4" src="https://i.imgur.com/ZcGeIVz.png" class="one" style="width:50px;height:50px">
<img id="5" src="https://cdn-icons-png.flaticon.com/512/734/734544.png" class="one" style="width:50px;height:50px">
<img id="6" src="https://cdn-icons-png.flaticon.com/512/734/734544.png" class="one" style="width:50px;height:50px">
<img id="7" src="https://cdn-icons-png.flaticon.com/512/734/734544.png" class="two" style="width:50px;height:50px">
<img id="8" src="https://cdn-icons-png.flaticon.com/512/734/734544.png" class="two" style="width:50px;height:50px">
<img id="9" src="https://cdn-icons-png.flaticon.com/512/734/734544.png" class="two" style="width:50px;height:50px">
<img id="10" src="https://i.imgur.com/ZcGeIVz.png" class="two" style="width:50px;height:50px">
<img id="11" src="https://i.imgur.com/ZcGeIVz.png" class="two" style="width:50px;height:50px">
<img id="12" src="https://i.imgur.com/ZcGeIVz.png" class="two" style="width:50px;height:50px">

I know how to use the AND operator with the function querySelectorAll when it's selecting only specific tags and classes like described in this answer. But I didn't manage to make it filter a class AND a specific attribute at the same time. On my sample, I'd like to filter all elements that belong to the class one and that have a src https://stackoverflow.com/a/36545002/14739472 (that would be the id 5 and the id 6)... I've tried using ., space, , but none of them work... I didn't find any example on how to do it when I'm specifying an attribute AND a class with querySelectorAll. How can I do it?

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