
Untitled
By: a guest on
May 9th, 2012 | syntax:
None | size: 0.61 KB | hits: 18 | expires: Never
// let's find all links to youtube
$('.content a[href^="http://www.youtube.com/watch"]').each(function() {
var linkHref = $(this).attr('href'),
vidIndex = linkHref.indexOf('v=') + 2,
videoId = linkHref.substring(vidIndex, linkHref.indexOf('&') >= 0 ? linkHref.indexOf('&') : (linkHref.length - vidIndex));
// let's change the link text for a easier read
$(this).text('original link');
// let's append the youtube embed code
$(this).prepend('<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/' + videoId + '" frameborder="0"></iframe><br/>');
});