Making a click event accessible

I thought adding a tabindex to an element which has a “click” event listener on it would make it accessible. I can tab to the element, but pressing Enter does not activate the event listener. What am I missing?

The JS

const pv = document.querySelectorAll(".playVid"),
  ib = document.querySelector("#vidbox");
for (let j = 0; j < pv.length; j++) {
  pv[j].addEventListener("click", function() {
    // stuff goes here
  })
};

The HTML

<div class="playVid" data-vid="34" tabindex="0">&#x23f5; Play video</div>
2 Likes

One is a wally!

Changed the div to a button and hey-presto, it all works…

(\_/)
( •_•)
/ >< \
5 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.