javascript - Add automatically an html code for every video in the blog -


i have many video in blog, classic code:

<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/slhhs7ic7m0?rel=0" width="640"></iframe> 

now want transform code above automatically, every post:

<div id="wr"> <div class="trigger open"><a href="#">open</a></div> <div class="cnt"> <div class="flex-video widescreen"><iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/slhhs7ic7m0?rel=0" width="640"></iframe></div> </div></div> 

how can in jquery?

jsfiddle file: https://jsfiddle.net/zzq91smv/2/

thank you!

try adding doc ready function:

    var template =  '<div class="wr">'+                     '<div class="trigger open"><a href="#">open</a></div>'+                     '<div class="cnt">'+                     '<div class="flex-video widescreen"></div>'+                     '</div></div>';      $('iframe').each(function(ind, ele){         var $ele = $(ele);         $ele.after(template);         $ele.next('.wr').find('.flex-video').append($ele);     }); 

see in action here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -