I have PHP while loop which showing this value:
echo "<a href='$video_url' data-vid='$video_id' class='$active'>$video_title</a>";
And I have a HTML iframe:
<iframe height="380" id="yframe" data-video-id="" width="800" src="https://www.youtube.com/embed/xxHmoLvjpLs" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen style="margin-top: 30px; float: right; margin-right: 10px; "></iframe>
How its works:
When I click on the each alink it's just getting the href value and set it to iframe src value.
Well, Now you see that I have data-vid value in a link.
I want, On first page load the first data-vid value should be set to iframe data-video-id value.
and then when I click on any a link then corresponding data-vid value should set to iframe data-video-id value.
But somehow it's not working.
here is my JS code:
<script>
$(document).ready(function(){
var current_vid = $('.vertical-menu a').data("vid");
$('#yframe').data('video-id', current_vid);
$(".vertical-menu a").click(function(e) {
e.preventDefault();
$("#yframe").attr("src", $(this).attr("href"));
$('#yframe').data('video-id', $(this).data("vid"));
$('.vertical-menu a').removeClass('active');
var $this = $(this);
if (!$this.hasClass('active')) {
$this.addClass('active');
}
})
});
$(document).ready(function(){
$("#next-btn").click(function(){
$(".vertical-menu a.active").next().trigger("click");
});
});
</script>