Solution 1 :

Try adding element to the iframe document body:

function Addcompntn() {
    var framedeki = document.getElementById('if1').contentWindow.document;   
    var div = document.createElement("div");
    div.id = 'innerdiv';
    div.style.color = 'white';    
    framedeki.getElementById('example').append(div);
}

Problem :

I want to add input in a div content javascript but it doesn’t add

HTML:

<button onclick="Addcompntn();" class="btn btn-success">Add</button>
<iframe class="embed-responsive-item" src="index.html" allowfullscreen id="if1"></iframe>

Script:

function Addcompntn() {
    var framedeki = document.getElementById('if1').contentWindow.document; 
    $('example').append('<div id="innerdiv" style="color:white;"></div>');
}

index.html

<div id="example" style="z-index:2"> //dynamic data will come here </div>

Comments

Comment posted by Taplar

Is the source of the iframe the same domain as the parent page?

Comment posted by developer.mozilla.org/en-US/docs/Web/HTTP/…

If it’s not on the same domain .. And you don’t have access to the

Comment posted by Muhammed

yes i’m working in the same directory and localhost

Comment posted by Muhammed

Thanks, it worked successfully and I can configure the div, but how can I add div inside div, not body

Comment posted by svyat1s

@Muhammed just get element that you need inside iframe and append that div to it. I’ve updated my answer.

By