Reputation: 12262
I am trying to append the value of the id of the image link the user clicks, to the iframe src to display the video to the user can play it.
I am able to capture the value from the id, but I don't know how to pass it dynamically to the iframe src
$(".play-video").click(function() {
alert("http://www.youtube.com/embed/" + this.id);
// append the id code into the iframe src=""
});
<div class="video-item">
<a href="#" class="play-video" id="B-5c8Z-I_x4"><img src="http://img.youtube.com/vi/B-5c8Z-I_x4/1.jpg"></a>
<br />10/15/2014
</div><!-- ./video-item -->
<div class="video-item">
<a href="#" class="play-video" id="kLRVk-rt1kg"><img src="http://img.youtube.com/vi/kLRVk-rt1kg/1.jpg"></a>
<br />10/15/2014
</div><!-- ./video-item -->
<iframe width="400" height="225" src="" class="user-picked-video" frameborder="0" allowfullscreen></iframe>
Upvotes: 0
Views: 2331
Reputation: 4724
with plain JavaScript its just:
var myIframe= document.getElementById('myIframe');
myIframe.src = "http://www.youtube.com/embed/" + myIframe.id;
Upvotes: 1