Reputation: 871
I am trying to play video only when the play button is clicked, using jQuery attr
but it doesn't seem to work. Here is a example. I want the video to have sound and play ONLY when button is pressed as i have another button linked to another video. Here is my codepen and my code is following,
jQuery(document).ready(function() {
jQuery(".glyphicon-play-circle").click(function() {
jQuery(".sports-video").css("display", "block")
jQuery("#bgvid").toggleClass("is-not-active");
jQuery(".fullscreen").toggleClass("is-video-active").attr("autoplay","true");
});
});
Upvotes: 0
Views: 3745
Reputation: 555
remove the autoplay
attribute in the <video>
.
To start the video do following in jquery:
$(document).ready(function() {
$(".glyphicon-play-circle").click(function() {
$('video').get(0).play();
});
});
If you want to play several videos on your website you should give the video a class and select the class direct instead of $('video')
Upvotes: 4