How to set focus style using JavaScript for each and every element returning in querySelector

Viewed 15

I wanna put styles to link: focus programmatically using java script, but my code only outputs the styles for the very first element on focus. any solutions?

 document.querySelectorAll(".page-collection").forEach(div => {
    div.querySelector("a").addEventListener("focus", function () {
       this.style.backgroundColor = "red";  
    })
  })
0 Answers
Related