Get YouTube Key from a Link

// Example link:
// <a id="myLink" href="">Youtube link</a>

var youtubeLink = document.getElementById('myLink').href;
var youtubeVideoKey = youtubeLink.substr(youtubeLink.lastIndexOf("v=") + 2, 11);

// youtubeVideoKey will return "cyRqR56aCKc"


  1. User Avatar
    Jeff Byrnes
    Permalink to comment#

    Amazingly timely! I was just trying to work this out myself when this showed up in my RSS feed; thanks!

  2. User Avatar
    Permalink to comment#

    I’ve been exploring for a little bit for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I finally stumbled upon this web site. Reading this information So i’m satisfied to express that I’ve an incredibly excellent uncanny feeling I found out exactly what I needed. I such a lot indisputably will make sure to do not forget this website and give it a glance on a continuing basis.

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.