Javascript jQuery

How to apply CSS to iframe?

setTimeout(() => {
    let myiFrame = document.getElementById("hs-form-iframe-0");
    let doc = myiFrame.contentDocument;
    doc.body.innerHTML = doc.body.innerHTML + '<style>form{margin:auto;}</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);
});

 

Leave a Reply

Your email address will not be published. Required fields are marked *