So I have a modal that displays a YouTube video. The problem is, when I close the modal, I still hear the video playing. I've looked at other solutions and they don't seem to work. Please keep in mind that I can't apply an ID to the iframe because the Iframe is created dynamically. Is there anyway to stop or pause the video using JavaScript or JQuery when I close the modal?
My code is below:
<script>
(function($){
$(document).ready(function() {
$('.b-close').on('click', function() {
$('iframe').get(0).stopVideo();
});
})(jQuery);
</script>
<div id="element_to_pop_up" attrId="20">
<a class="b-close">x</a>
<h3 class="pop-hd">Title</h3>
<div class="pretty-embed play" data-pe-videoid="nGSfaMxCu-U" data-pe-fitvids="true" data-pe-allow-fullscreen="false">
<iframe width="330" height="186" style="border:none;" src="//www.youtube.com/embed/nGSfaMxCu-U?autoplay=1&rel=1"></iframe>
</div>
</div>