JavaScript - - By Sam Deering

jQuery Replace YouTube Links with Flash Video


jQuery code snippet to replace all links with embed flash video on web page or blog post/page.


Go to, find the video (for example, copy link and paste it in your page/blog post. Change in script width and height to your desired parameters and change ‘#blog .post’ to your page content container or blog post container.

    var vidWidth  = 459; // youtbe video width
    var vidHeight = 283; // youtube video height
    var obj       = '' +
        '' +
        '' +

    $('#blog .post').find('p:contains("")').each(function(){
        var that = $(this);
        var vid = that.html().match(/(?:v=)([w-]+)/g);
        if (vid.length) {
            $.each(vid, function(i){
                that.replaceWith( obj.replace(/[vid]/g, this.replace('v=','')) );

See live demo