How do I find the element by matching its CSS property value?
For example, if the background color of the element is green, then do something…
const elm = document.getElementsByClassName('elm');
[...elm].forEach(function(s) {
//find the element which background color is green
//then console.log(theItem)
})
.elm {
width: 200px;
height: 100px;
}
.elm1 {
background-color: red;
}
.elm2 {
background-color: green;
}
.elm3 {
background-color: blue;
}
<div class="elm elm1"></div>
<div class="elm elm2"></div>
<div class="elm elm3"></div>