Adding a Class to a Parent when Child is Hovered using JavaScript | Tutorial

PHOTO EMBED

Wed Mar 02 2022 19:31:18 GMT+0000 (Coordinated Universal Time)

Saved by @shawna

document.addEventListener("DOMContentLoaded", (event) => {
  const videoCardLinks = document.querySelectorAll(".video-card__link");

  videoCardLinks.forEach((el) => {
    el.addEventListener("mouseover", (e) => {
      e.target.closest(".video-card").classList.add("hovered");
    });
    el.addEventListener("mouseout", (e) => {
      e.target.closest(".video-card").classList.remove("hovered");
    });
  });
});
content_copyCOPY

https://wpdevdesign.com/adding-a-class-to-a-parent-when-child-is-hovered-using-javascript/