The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Programming Fundamentals" Dec 02 - 2:00 PM Eastern

Get YouTube Key from a Link

Last updated on:
// 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. 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. diëtist
    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

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed