How to pause a YouTube video on button click?

Problem

<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?

Problem courtesy of: Ilja

Solution

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

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

See an example here

Solution courtesy of: jacktheripper

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.