Reputation: 578
I have a div element which is a link and I want it to be able to play a video once again. My jQuery code is this :
$('#film').click(
function() {
$('#question').hide();
$('#video').show();
});
I know that the YouTube javascript API has a player.playVideo()
function but I can't figure out how to implement it inside my jQuery function.
Upvotes: 0
Views: 916
Reputation: 578
I found out with the help of Hidden youtube player loses its methods that it was because I was hiding and showing back the player.
I changed it to $('#video').css('visibility','hidden');
for hiding and $('#video').css('visibility','visible');
for showing it back and it works. My final code is :
function play() {
if (ytplayer) {
ytplayer.playVideo();
}
}
$('#film').click(
function() {
$('#question').hide();
$('#video').css('visibility','visible');
play();
});
Upvotes: 1