How can you stop a YouTube video from playing in an Iframe with JavaScript or Jquery?
<p>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? </p>

<p>My code is below:</p>

<pre><code>&lt;script&gt;
(function($){
  $(document).ready(function() {
  $('.b-close').on('click', function() {
   $('iframe').get(0).stopVideo();
  });
})(jQuery);
&lt;/script&gt;



 &lt;div id="element_to_pop_up" attrId="20"&gt;
   &lt;a class="b-close"&gt;x&lt;/a&gt;
   &lt;h3 class="pop-hd"&gt;Title&lt;/h3&gt;
   &lt;div class="pretty-embed play" data-pe-videoid="nGSfaMxCu-U" data-pe-fitvids="true" data-pe-allow-fullscreen="false"&gt;

   &lt;iframe width="330" height="186" style="border:none;" src="//www.youtube.com/embed/nGSfaMxCu-U?autoplay=1&amp;amp;rel=1"&gt;&lt;/iframe&gt;

   &lt;/div&gt;

  &lt;/div&gt;
</code></pre>