click on a button play on YouTube iframe


I have iframe of Youtube, and a div over it, I want it when the user clicks on that div it plays in the video. My HTML:

<div class="p-relative">
    <div class="botaoMaior">
        <div class="btplay"></div>
    <div class="editable videoMaior" name="videoMaior">
    <iframe width="960" height="780" src="//" frameborder="0" allowfullscreen=""></iframe>

I would like something from the Tupo:

 $( ".botaoMaior" ).click(function() {
  $( ".botaoTeste" ).click();
asked by anonymous 02.02.2015 / 11:33

3 answers


You can do this in a very simplified way using the autoplay=1 parameter in querystring:

$('#image_id').click(function() {
    $(".frameVideo").attr('src', $(".frameVideo").attr('src') + '?autoplay=1'); 

<button id="image_id">Play</button>
<iframe class="frameVideo" src="//" frameborder="0" allowfullscreen=""></iframe>

Where image_id is the id of your image or clickable button and .frameVideo is the class of <iframe>

Example online (snippets run in SandBox and therefore do not support cross-origin): link

02.02.2015 / 11:59

Include the youtube API script and replace your iframe with a div with an id to be able to identify it:

<script src=""></script><divclass="editable videoMaior" name="videoMaior">
    <div id="meuPlayer"></div>

Then in JS you can use the API as documentation :

var player = new YT.Player('meuPlayer', {
    width: 540,
    height: 320,
    videoId: 'eX0IjD5DPQI'

$(".botaoMaior").on("click", function() {

JSFiddle Example

In this example, div#meuPlayer server to identify where iframe will be inserted. iframe will replace with div . When calling the YT.Player method, a new object related to the video player will be created and returned, which can be used to control the player functions in a number of ways. See this link for the functions available for this object.

06.02.2015 / 16:15

You can not manipulate DOM documents from an iframe that points to a different domain from the page that contains it. What you can do in this case to have greater control over the player is to use the Youtube Embbed API.


Using the API you could have something like the one below to play the video.

$( ".botaoMaior" ).click(function() {
06.02.2015 / 15:00