Ilja
Ilja

Reputation: 46479

How to pause a YouTube video on button click?

<a href="#page" class="lil-close">Close</a>

I have this button to close a lightbox. The lightbox contains a YouTube video and when I close the lightbox YouTube video keeps playing, I assume this will happen with all videos (not only YouTube). Is there a way (jQuery/JavaScript) to pause video once a user clicks a button?

Upvotes: 0

Views: 3996

Answers (1)

jacktheripper
jacktheripper

Reputation: 14219

Try this function which uses YouTube's API and YouTube's Chromeless Player:

function pauseVideo() {
  if (ytplayer) {
    ytplayer.pauseVideo();
  }
}

See an example here

Upvotes: 3

Related Questions