There are three divs and each of them got a different value of the transform
property.
I save them into a variable by getElementsByClassName
and then use the find
method to find the element in which the transform
is 10px.
However, it's not working because the error in the console said that is 'undefined' which means it cannot be found I guess...
What am I doing wrong?
const elm = document.getElementsByClassName('elm');
const elms = [...elm].find(function (s) {
const item = getComputedStyle(s).transform;
return item === 'translateX(10px)';
});
console.log(elms);
.elm1 {
transform: translateX(-20px);
}
.elm2 {
transform: translateX(10px);
}
.elm3 {
transform: translateX(20px);
}
<div class="elm elm1"></div>
<div class="elm elm2"></div>
<div class="elm elm3"></div>