Reputation: 6117
I created an iframe and set the source to an empty page which is already created too. The problem is how to dynamically add some html chunk (the html is already stored in a variable) inside a div on the empty page and then display it on the iframe. I'm using jquery. Thanks
Upvotes: 2
Views: 157
Reputation: 348962
Select the iframe, then use .contents()
to access the jQuery-wrapped document object of the iframe (same domain-only!).
var chunk = "<a>Test</a>";
var iframeBody = $("#id-selector-of-iframe").contents().find("body");
iframeBody.append(chunk);
//Or, if you want to overwrite the body:
//iframeBody.html(chunk);
Upvotes: 4