0

I'm using this script to pause a video when clicking on the close button:

var vid = document.getElementById("video19"); 
$('#md-close').click(function(){
vid.pause();
});

but if I have more than one video, I can't use id for that. I tried to use getElementByClassName but it didn't work even in the last version of chrome.

so I want one script that pauses the current video when I click on close button. how can I do that?

BMARK AMIT
  • 77
  • 1
  • 11
  • Possible duplicate of [How can I pause ALL videos (html5) at once?](https://stackoverflow.com/questions/13485167/how-can-i-pause-all-videos-html5-at-once) – Arvind May 28 '17 at 10:04

1 Answers1

0

If you place both video and relative close button in the same div you can do that. I'm supposing a unique div for each video.

<div>
    <video><!-- some code --></video>
    <a class="close-button">Close video</a>
</div>
$('.close-button').click( function(){
    $( this ).siblings('video').get(0).pause()
})
a.barbieri
  • 2,398
  • 3
  • 30
  • 58