I’ve created a div which I want to fill with a different embedded video based on which link within a series of links below that div gets clicked by a user. Currently, the function only works only for the top link in the list. Clicking on any of the links under the first produces no effect. Here’s the JS:
$(document).ready(function(e){
$('a.videoBoxLinks').bind('click',function(e){
var vidUrl = $(this).attr('href');
var vidBox = $(this).prev('.videoBox');
vidBox.html('<iframe src="' + vidUrl + '" width="400" height="300" frameborder="0"></iframe>');
e.preventDefault(); //stops the browser click event
});
});
and the HTML
<div class="videoBox">
<h1>default content to be replaced</h1>
</div>
<a class="videoBoxLinks" href="videoURL1">Test 1</a></br> <!--this one works-->
<a class="videoBoxLinks" href="videoURL2">Test 2</a> <!--this one doesn't-->
Check the following code. It works for me.
HTML:
Script: