0

I have a Vimeo URL that looks like this:

<iframe src="https://player.vimeo.com/video/57418480?byline=0&portrait=0&autoplay=1" width="620" height="350" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

What I want to do is take the video ID, which in this case is 57418480 and replace it onclick. I would have the ID set via the class attribute. For example:

<li><a href="#" class="57418481">Ethics in Investing</a></li>

Clicking the above link would replace just the number ID, so it would then look like this:

<iframe src="https://player.vimeo.com/video/57418481?byline=0&portrait=0&autoplay=1" width="620" height="350" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

2 Answers 2

2

Use data-url in your link

<li><a href="#" data-url="https://player.vimeo.com/video/57418481?byline=0&portrait=0&autoplay=1" class="57418481">Ethics in Investing</a></li>

onclick:

$('a').on('click',function(){
  $('iframe').attr('src',$(this).data('url'));
});
Sign up to request clarification or add additional context in comments.

1 Comment

This is actually a better way of approaching the problem.Thanks for your answer, it worked great! :)
1
$('a').click(function() {
    var newID = $(this).attr('class');
    var newURL = 'https://player.vimeo.com/video/' + newID + '?byline=0&portrait=0&autoplay=1';
    $('iframe').attr('src',newURL);
    return false;
});

http://jsfiddle.net/Khpd7/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.