Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // let's find all links to youtube
  2. $('.content a[href^="http://www.youtube.com/watch"]').each(function() {
  3.  
  4.         var linkHref = $(this).attr('href'),
  5.             vidIndex = linkHref.indexOf('v=') + 2,
  6.             videoId = linkHref.substring(vidIndex, linkHref.indexOf('&') >= 0 ? linkHref.indexOf('&') : (linkHref.length - vidIndex));
  7.        
  8.         // let's change the link text for a easier read
  9.         $(this).text('original link');
  10.        
  11.         // let's append the youtube embed code
  12.         $(this).prepend('<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/' + videoId + '" frameborder="0"></iframe><br/>');
  13. });