JS - change iframe body style for vanilla and jQuery

0 votes
23 views
added May 15 in Javascript by lcjr First Warrant Officer (11,930 points)
recategorized May 16 by lcjr
// vanilla
document.addEventListener('DOMContentLoaded', function() {
  var iframe = document.querySelector('.your_classname');

  if (iframe) {
    iframe.addEventListener('load', function() {
      var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
      iframeDoc.body.style.marginTop = '83px';
    });
  }
});


// jQuery
var iframe = $('.your_classname').find('iframe');

iframe.on('load', function() {
    $(this).contents().find('body').css('margin-top', '83px');
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...