As a novice in the world of Javascript, I am currently attempting to select an element within an array of images where the opacity
is set to 1
. Could someone please guide me on how to achieve this? I've tried using hasAttribute
, but I'm unsure how to compare it with ==1
as it's yielding unexpected results.
<ul id="fullscreenImagesList">
<li><span class="fullscrnImgs"></span></li>
<li><span class="fullscrnImgs" style="opacity: 1;"></span></li>
<li><span class="fullscrnImgs"></span></li>
<li><span class="fullscrnImgs"></span></li>
<li><span class="fullscrnImgs"></span></li>
</ul>
Now let's take a look at the JavaScript snippet:
var bigImages = [].slice.call(document.getElementsByClassName("fullscrnImgs"));
for (var i = 0; i < bigImages.length; i++) {
var opac = bigImages[i].getAttribute("opacity");
console.log(opac);
}