Mario Parra Mario Parra - 2 years ago 127
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.


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

Any help would be appreciated. Thanks!

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download