I have a page that has multiple videos embedded. Each link opens up the video in bootstraps modal. The problem I have is if I close the modal the video is still playing.
I found a script that will force this to stop but then my next issue was the page has multiple videos. So I have tried to capture the id of each video into a variable when clicked.
Independently the two scripts I have work, bit what am I missing to get them combined?
HTML
<ul>
<li><a class="video" href="#" data-toggle="modal" data-target="#video1">Video 1</a></li>
<li><a class="video" href="#" data-toggle="modal" data-target="#video2">Video 2</a></li>
<li><a class="video" href="#" data-toggle="modal" data-target="#video3">Video 3</a></li>
<li><a class="video" href="#" data-toggle="modal" data-target="#video4">Video 4</a></li>
</ul>
This is the jQuery I have to stop the video from playing:
$('#video1').on('hidden.bs.modal', function (e) {
$('#video1 iframe').attr("src", jQuery("#video1 iframe").attr("src"));
});
And here is the variable I set up to capture the ID of the clicked link so I don't have to add each ID manually to the script above:
$('a.video').click(function(e) {
editid = $(this).attr("data-target");
alert(editid);
});
What I am struggling to find out is how to add the variable and get it to work in the first jQuery part that stops the video from playing on close.
Thanks