Dynamically Load Youtube Video Iframe embed Code inside a DIV

[UPDATED : The code has been updated to work in latest version of Firefox. May 20,2014]

By storing or by having the Iframe embed code as a variable, You can play the Youtube video on a click of a button or any other event.  I have used “append” function of jQuery to append the IFrame code dynamically inside a DIV tag.

Check the Demo Page for Loading YouTube Video Embed Code Dynamically

How it Works :

The textarea contains the iframe code.  Please note that you can embed any Youtube Iframe embed code and click on the button.  The button is just a link.  It uses “event.preventDefault(); ” function to avoid page refresh.

I have tested it in IE, Firefox.  Please check in your browsers too.  Please comment and enhance the code.

Load YouTube Video Dynamically inside a DIV

Load YouTube Video Dynamically inside a DIV

(Visited 224 times, 1 visits today)

You may also like...

Leave a Reply