I am using Javascript to play an HTML5 video when you hover over it, and then pause the video once the mouse exits. The module is working correctly in that sense, except it only works for the first video on the page. There are seven videos total, all using the same div structure.
You can see this in action here: https://dcd.gdr.mybluehost.me/website_33a4bb40/
Following is the JS file that I am using:
jQuery(document).ready(function($){
const video = document.querySelector(".video-container video");
video.addEventListener("mouseenter", () => {
video.play();
});
video.addEventListener("mouseleave", () => {
video.pause();
});
});
And following is the HTML that contains the video:
<div class="video-container">
<video
src="https://dcd.gdr.mybluehost.me/website_33a4bb40/wp-content/uploads/2025/10/cael-dadian-portfolio-iphone-beat-packs-1.mp4"
muted="muted"
poster="https://dcd.gdr.mybluehost.me/website_33a4bb40/wp-content/uploads/2025/10/cael-dadian-portfolio-thumbnail-iphone-beat-packs-1.jpg">
</video>
</div>
I am not seeing any console errors in the inspector. Thank you
querySelectorreturns one single element (or null, if not found.) You need to usequerySelectorAllinstead, and then iterate over the resulting NodeList.const video = document.querySelectorAll(".video-container video");But now I am getting the console error:video.addEventListener is not a functionThoughts?