Reputation: 61
When I click on close button, I stopped video but it changed the video URL too. and when I open any popup after closing, all popup's showing 1 video.
this the javascript code which I am working
var videoSRC = jQuery('.hide_overlay iframe').attr('src');
jQuery('.close_me').click(function (e) {
jQuery('.hide_overlay iframe').attr('src', videoSRC);
});
Upvotes: 2
Views: 2687
Reputation: 36
If I understand correctly, you have multiple popups? If so, the code to change the src will affect all dialogs.
I'm assuing you're changing the SRC to stop the video. Also, assuming that the .close_me
element is within the .hide_overlay
element, you can do this:
jQuery('.close_me').click(function (e) {
var $videoEl = jQuery(this).closest('.hide_overlay').find('iframe');
$videoEl.attr('src', $videoEl.attr('src'));
});
This works because jQuery(this)
will target the specific close button related to that one popup, and not target all popups.
Technically, a nicer way to stop or pause a video is to use the Youtube Javascript API as you can do something like:
player.stopVideo();
Upvotes: 1