Reputation: 1617
I need to play the video on "Play" button click on a site
I tried using this code but it doesn't trigger the play on the Youtube Video.
jQuery(document).on('click', '.eg-henryharrison-element-2', function(event) {
event.preventDefault();
jQuery(".esg-youtubevideo").click();
});
Upvotes: 0
Views: 3217
Reputation: 566
This should work
$('.esg-youtube-frame').each(function(){
var src = $(this).data('src');
src += "&autoplay=1";
$(this).data('src',src);
});
Upvotes: 1
Reputation: 1882
Maybe I don't understand what you actually want to achieve, but:
For me the following works:
$('.esg-click-to-play-video').first().click()
See here:
After:
Upvotes: 2
Reputation: 566
You should try adding autoplay=1
option to your iframe src like this
<iframe width="420" height="345" src="https://www.youtube.com/embed/qYcSef6Mk58?version=3&enablejsapi=1&html5=1&controls=1&autohide=1&rel=0&showinfo=0&fs=1&playsinline=1&autoplay=1" frameborder="0" allowfullscreen></iframe>
Here is a related question already been asked at stack overflow: YouTube Iframe embed auto play
Upvotes: 3