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?