In my code, I have three div elements with different values of the transform
property assigned to them.
I store these elements in a variable using the getElementsByClassName
method and then try to find the element where the value of the transform
property is 10px by using the find
method.
However, I am encountering an issue where the console displays an error stating that the value is 'undefined', indicating that the element cannot be found. What could I be 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>