Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change HTML of an iFrame with jQuery?

Tags:

jquery

iframe

Is there a way to manipulate the HTML of an iframe that is from the same domain using jQuery?

Thanks for the help.

like image 977
Stephen Ou Avatar asked May 08 '11 00:05

Stephen Ou


People also ask

Can you change HTML in an iframe?

HTML's DOM, or Document Object Model, lets you replace an iframe's HTML code by giving JavaScript's getElementById function access the "src" attribute. Each iframe must be labeled with a unique ID selector.

Can you use jQuery in an iframe?

However, it's also possible to use a really simple jQuery to access the elements within the iFrame. Check it out below: $(document). ready(function(){ var iFrameDOM = $("iframe#frameID").

How can get iframe HTML using jQuery?

# jQuery Code to Get HTML Content of IFrame$("#myButton"). on('click', function() { alert($("#myIframe"). contents(). find("html").

Can I change content of iframe?

When you can communicate with the code inside an iFrame, you can make any change you want to the code within that iFrame.


2 Answers

You'll have to parse the iframe content.

$("#frameid").contents().find("div").html('My html'); 

More here : http://api.jquery.com/contents/

like image 74
c0mm0n Avatar answered Sep 24 '22 12:09

c0mm0n


You can use contents() to manipulate the contents of the iframe.

$("#frameDemo").contents().find("div").html("new HTML content goes here"); 
like image 44
Town Avatar answered Sep 22 '22 12:09

Town