I want to pass the myVideo element as a parameter in the play() function, but it does not work? (It is auto-playing the video instead and the eventListener no longer works)
If I use the element directly in the function it work. So I am wondering is it ever possible to pass a DOM element as a parameter and if so is it ever used
Here is the code below:
// Get our elements
const myVideo = document.querySelector(".player__video");
const playButton = document.querySelector(".player__button");
console.log(myVideo);
function play(video) {
if (video.paused) {
video.play();
} else {
video.pause();
}
}
playButton.addEventListener('click', play(myVideo))