I am trying to determine what is the most efficient way to load a video in a user click using jQuery.
To add more context, I will have about 30 clips on YouTube, each of which takes 30-60 seconds, and I would like to dynamically upload them to a div on the right side of the page when a user views topics and potential video clips on the left side.
Right now, I have configured this HTML and jQuery. This works, but I'm curious if there is a better way:
<div class="wrapper"> <div class="details_left"> <div class="cluster"> <a href="#" id="johnk" class="vid_trigger"><div class="title">The importance of demonstrating intellectual curiosity</div></a> <div class="role">John K: Summer Consultant, BCG</div> <div class="summary">Discussion on how curiousity is important to show in interviews because it leads to better answers on the job</div> </div> </div> <div class="details_right" id="video_container"> video </div> </div>
And jQuery:
$('#johnk').click( function(){ $('#video_container').html('<iframe width="425" height="349" src="http://www.youtube.com/embed/bMvRdr-mUOU?rel=0" frameborder="0" allowfullscreen </iframe>'); })
To reduce the manual coding of .click () for each video, I am considering creating an associative array with the ids-> embed index. Is there a better way to more effectively implement the same functionality?
Thanks in advance for any ideas!
source share