How can I make a function work on multiple elements?
let image = document.getElementById("opacityLink");
image.onmouseover = function() {
image.style = "opacity:0.9";
};
image.onmouseout = function() {
image.style = "opacity:1";
};
<div class="news col-xxl-4 col-xl-4">
<a href="/index.html" id="opacityLink" name="opacityLink">
<div class="img-news">
<img src="img_nature.jpg" alt="Image">
</div>
<div class="info-news">
<div class="date">
2023.07.02
</div>
<div class="title-news">
<h2>Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, soluta.</h2>
</div>
<div class="excerpt-news">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit sed perspiciatis nihil voluptas qui quaerat tempore quibusdam inventore reiciendis, minima tempora quasi.</p>
</div>
</div>
</a>
</div>
I have tried using getElementsByClassName and getElementById but it's not working. When using ID, only one link works, but I have 9 similar links and I want the JavaScript code to apply to all 9.