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

97
Visualizações
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
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