Word Count: 102
  • Post category:RE Collective (21)
  • Post last modified:2021-12-27

Introduction

While a video or Youtube is playing and is then switched to background, for example, by clicking a tab, the video continues to play in the background which is undesirable. To remove this effect, it is possible to use JS or jQuery to remove the value of ‘src’ attribute and then immediately add it back.

Sample Code

jQuery('.cu-single-listing-tabs ul').on('click', 'li', function () {

    if (tabID != 'cu-tab-video') {			
			//stop video playing in background
			var video = jQuery('#cu-tab-video-content iframe').attr('src');
			jQuery('#cu-tab-video-content iframe').attr("src","");  //remove the value
			jQuery('#cu-tab-video-content iframe').attr("src",video); //add back the value
	}

});