Skip to content
Advertisement

pause the other playing video when play a new video jquery

I have many videos on one page. I am using jquery to play and pause the videos when I click on the play button it should play. I did this using jquery. now I need to pause the other videos when I press play on the next or previous video. could you help me, please?

a screenshot is here

JavaScript
JavaScript

Advertisement

Answer

To do what you require you can create a function which loops through all video elements and calls pause() on then. You can then call this function when a video is played.

In addition, note that instead of looping through the video elements on document.ready, you can instead attach event handlers to the media control buttons which use DOM traversal to find the related content when they are clicked. This has the benefit of simplfying the code, and maknig it easier to maintain. Try this:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement