tags:

views:

33

answers:

3

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>
+2  A: 

Something like this should get you out of trouble:

$(function()
{
    $('div[class=video] > a').click(function() 
    {
        $('div.video-caption').html($(this).attr('rel'));
    });
});
Boycs
Doesn't seem to work - no javascript errors though. Here's a test page: http://vincent-massaro.com/append/test.html
It is not working because you need to run this code when the DOM is ready. The code given works perfectly. Also, `div[class=video]` could be written as `div.video`.
Anurag
@user310404 - you need to add that code on document.ready. You can do that with `$(document).ready(function(){ ..YOUR CODE.. });`
Krunal
That did it! Thanks for the help!
Updated the answer for completeness to include the doc ready
Boycs
A: 

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"));
}
Krunal
A: 

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>
mohamadreza