On this page I have two divs, div-1 overlapping another div-2 http://55-corinthian-drive.webflow.io/home-video-wip
Div-1 houses the play button (and large image and text), on clicking the play button div-1 toggles off revealing div-2 which houses a Vimeo video. I want the video to start playing once the button is clicked but am unable to get it working. Below is my script for removing div-1 which works fine. I have looked at this idea https://jsfiddle.net/ELHCm/ but wasn't able to get that working, am trying $("#id").vimeo("play"); now.
<!-- triggering div -->
<div class="video-trigger-wrap">
<h1 class="header">text to remove on click</h1>
<div class="video-trigger"></div>
</div>
<!-- video -->
<div class="div-block-23 position-vid">
<div id="w-node-df98048f0945" class="video-4 w-video w-embed">
<iframe id="g-vid" src="video-address" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
</div>
<script>
$(document).ready(function(){
$(".video-trigger").click(function(){
$(".video-trigger-wrap").toggle();
$("#player").vimeo("play");
});
});
</script>
Also tried the following, as suggested by Charan below, but has not worked.
<script>
$(document).ready(function(){
$(".video-trigger").click(function(e){
e.preventDefault();
$(".video-trigger-wrap").toggle();
$("#g-vid").vimeo("play");
});
});
</script>
Try 'on click' event instead of click event, because you are dynamically appending iframe
$('a').on('click',function(e) {
e.preventDefault();
$('#video_container').html('<iframe src="https://player.vimeo.com/video/12345?title=1&byline=1&portrait=1&autoplay=true" width="643" height="360" frameborder="0"></iframe>');
})