I have the following questions. I have html code below where I have a button that when clicking it opens a modal and starts playing a video. I also have the JavaScript code that picks up check the video id, change the display from name modal to block and play in the video. But this page will have more than 20 videos and I would like solution that could use for all elements.
var vid = document.getElementById("myVideo1");
var modal = document.getElementById("myModal");
var btn = document.getElementById("myBtn");
var span = document.getElementById("close");
btn.onclick = function(e) {
e.preventDefault();
modal.style.display = "block";
vid.play();
}
span.onclick = function(e) {
e.preventDefault();
modal.style.display = "none";
vid.pause();
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
vid.pause();
}
}
<div id="myModal" class="modal">
<!-- Conteúdo do Pop-up -->
<div class="modal-content" style="max-width: 100%;">
<span id="close" class="close"> <p class="btn" onclick=pauseall()>Close</p></span>
<video id="myVideo1" class="video-js vjs-default-skin video_size " controls preload="none" data-setup='{}'>
<source src="media/video.mp4" type="video/mp4">
</video>
</div>
<button id="myBtn" class="btn">Play</button>
</div>