Last Updated: February 25, 2016
· carlosagile

How to pause a video/audio when modal windows is closed

  • Example of how to pause a video or audio contained in a bootstrap-modal to prevent further hearing when the modal window is closed.
// Close Bootstrap Modal.
$('.close, .save, .cancel').on('click', function(e){
    var $this = $(this);
    // get identifier modal window.
    var modal = $'custom');

  // check tag html5 for video and audio.
   if (($('#id-'+modal).prop("tagName") == 'AUDIO') 
   || ($('#id-'+modal).prop("tagName") == 'VIDEO')) {
       if (!$('#el-'+modal).get(0).paused) {