YouTubin’ Plugin for jQuery


YouTubin’ is a jQuery plugin that makes embedding YouTube videos clean, easy and unobtrusive. In its simplest form, YouTubin’ grabs any links that point to a YouTube page and replaces them with an embedded video. To do so, YouTubin’ leverages SwfObject 2 if available, but otherwise just embeds the video through standard markup.

Advanced options include flagging specific video elements using a jQuery selector and setting a variety of swf properties such as dimensions, flash version, flashvars and params. Youtubin’ can even be used to cause the video to embed once a link is clicked rather than when the page loads.

Download YouTubin’ jQuery Plugin

How to use YouTubin’

Basic YouTubin’ is extraordinarily simple. Just include the Javascript files for jQuery, YouTubin’ and optionally SwfObject 2, then write:

$(function() {

This will pull in any links to YouTube video pages and replace them with an embedded video.

If you only want to replace certain links, say those with the class “youtube”, you can call YouTubin’ from any jQuery selector:

$(function() {

If you want, you can pass custom options as an object in the first argument of youtubin():

$(function() {
        swfWidth : 400,
        swfHeight : 360

Here we are setting the dimensions of the embedded video to 400px wide and 360px tall. Among the other options you can set replaceTime: 'click' if you want YouTubin’ to embed the video when a user clicks on the link rather than replacing all the links automatically. For a complete list of options please check the YouTubin’ documentation.

Finally, for best results with any method, include the Javascript for SwfObject 2 and YouTubin’ will automatically leverage it.

Download YouTubin’ jQuery Plugin

Jon Raasch

Jon Raasch is a UX nerd and free-lance web designer / developer who loves jQuery, Javascript & CSS.

You Might Also Like:

12 Comments to “YouTubin’ Plugin for jQuery”

  1. Amir says:

    Hey, nice plugin. Does it also work for links that just have or or in them?

  2. M2E says:

    I’ve been looking for this.
    At first I found oembed, but not suite my needed.
    Finally I found YouTubin. This is very useful plugin.

    Awesome man!!

  3. Micah says:

    Sweet plugin. This looks to be exactly what I need. I was just about to write the exact same thing, except crappier, I’m sure.

  4. jon says:

    I saw on a forum:, that this plugin can be used to embed youtube videos on a https page without making a non-secure call, which will cause IE to produce its non-secure warning. I checked through your documentation, and didnt see any mention of this. Im using prototype instead of jquery and would consider switching if I can make this work with your plugin, but I was hoping you could give me a bit more explanation of how it works.

    Im loading one video per page, and already have the full embed code on the page, but Im willing to make whatever changes necessary in order to avoid the nasty IE warning.


  5. Peter says:

    I have th exact same request as Jon. Your Plugin is very useful to avoid the non-secure warnings and have Youtube movies on a ssl website.

    How can we do that? I too find it hard to understand…


  6. Robert says:

    My theory about why this works on an https page is that browsers just aren’t smart enough to detect, post-javascript-processing, the embed that used to be a link. You can link to a http page all you want in https and not get a browser warning. And if you include javascript that does a simple document.write of an embed that contains a http source attribute on an https page, you’ll get a warning. But this code, which goes in and alters the DOM, flies under the radar. Just my theory. Haven’t tested it yet.

  7. Peter says:

    I read this comment on a page:

    “Neither swfobject nor youtubin works in FF 3.6.12. The small warning icon is displayed in the status bar footer, indicating that the page contains unsecure elements.”

    So I think we where cheering to soon…

    I’ve been into this for a year now and still no solid cross-browser solution.

  8. Michael says:


    It’s great plugin, but unfortunately stopped working after the last JQuery library update. With jQuery 1.6 it throws JS error:

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3; .NET4.0E)
    Timestamp: Tue, 17 May 2011 10:11:20 UTC

    Message: ‘length’ is null or not an object
    Line: 79
    Char: 17
    Code: 0
    URI: http://……/jquery.youtubin.js

  9. Marcell says:

    Replace line 79 — if ( !boxId.length ) { —
    with — if ( !boxId ) { —

    to make it work with the latest jQuery.

  10. Steve says:

    I tried everything including Marcell’s solution. Using Safari or Firefox I still get the message “boxid is not defined”. jquery 1.8.0

    I’m about to call it a day and give up having spent so much time on this.

  11. Alexander says:

    Replace line 40 with:

    $(“a[href^=’’]”, options.scope).youtubin(options);

    to fix an error with the default selector in the latest versions of jQuery.

  12. pcout says:


    Is it possible with this plugin to track the you tube videos embeded with the track event analytics code ?

    If so, how ?


Comments are closed.