How to apply CSS to iframe?

How to apply CSS to iframe?

December 29, 2022
setTimeout(() => {
    let myiFrame = document.getElementById("hs-form-iframe-0");
    let doc = myiFrame.contentDocument;
    let style = '<style>form{margin:auto;}</style>';
    doc.body.innerHTML = doc.body.innerHTML + style;
}, 5000);

//OR
jQuery(document).ready(function () {
    setTimeout(() => {
        jQuery("#hs-form-iframe-0").contents().find("form").css("margin", "auto");
    }, 5000);
});

//OR
$("iframe").on("load", function () {
    let head = $("iframe").contents().find("head");
    let css = '<style>#hsForm_25ec90f4-97be-40ee-b03b-dea0a1c9036e{margin:auto;}</style>';
    $(head).append(css);
});

 

One Comment

  1. Vivien September 10, 2023 at 5:02 am - Reply

    Appreciation to my father who informed me concerning this web site, this blog is really remarkable.

Leave A Comment