Mario Parra Mario Parra - 7 months ago 26
Javascript Question

Script to resize embedded YouTube videos

I'm trying to write a jQuery script that resizes all embedded YouTube videos to 746px x 420px, but it's not having any effect.

I'm using this approach as I recently adjusted my website's layout and I can't really go back and update the iframes individually. I've got separate CSS handling responsiveness.

Script:

jQuery('iframe[src^="//www.youtube.com"]').attr('width', '746px').attr('height', '420px');


Any help would be appreciated. Thanks!

Answer
jQuery(document).ready(function($){

$('iframe[src*="youtube.com"]').each(function() {
    var url = $(this).attr("src")
   $(this).attr('width', '73px').attr('height', '42px');
}); 

});