I am looking to read the rel value of an anchor and append it to a div when clicking on a link that loads in a video from Youtube into my player. A quick code dump is below. When a link is clicked, the rel value should append to the video开发者_高级运维-caption div. Thanks!
<div class="video">
<a onclick="player('http://www.youtube.com/v/ylJOn4dEKo0')" href="javascript:void(0);" rel="This is video one.">Video 1</a>
</div>
<div class="video">
<a onclick="player('http://www.youtube.com/v/gXRbiqm-HJA')" href="javascript:void(0);" rel="This is video two.">Video 2</a>
</div>
<div id="video-container">Video plays here</div>
<div class="video-caption">Video caption appended here</div>
</div>
Something like this should get you out of trouble:
$(function()
{
$('div[class=video] > a').click(function()
{
$('div.video-caption').html($(this).attr('rel'));
});
});
Here you go...
<div class="video">
<a onclick="player('http://www.youtube.com/v/ylJOn4dEKo0');UpdateTitle(this);" href="javascript:void(0);" rel="This is video one.">Video 1</a>
</div>
<div class="video">
<a onclick="player('http://www.youtube.com/v/gXRbiqm-HJA');UpdateTitle(this);" href="javascript:void(0);" rel="This is video two.">Video 2</a>
</div>
JS:
function UpdateTitle(obj)
{
$(".video-caption").html($(obj).attr("rel"));
}
this code is working fine for me
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".video a").click(function () {
$(".video-caption").text($(this).attr("rel"));
});
});
</script>
精彩评论