$(document).ready(function(){ $('#button').click(function(){ $('.accordion').load('<iframe src="google.com" frameborder="0" scrolling="no" id="myFrame"></iframe>'); }); });
This can't display the iframe of google.com. Can anyone provide suggestions on how to fix it?
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").
# jQuery Code to Get HTML Content of IFrame$("#myButton"). on('click', function() { alert($("#myIframe"). contents(). find("html").
Answer: Use the jQuery contents() method You can use the jQuery contents() method in combination with the find() , val() and html() methods to insert text or HTML inside an iframe body.
jQuery's load function isn't used this way. It takes a URL as a parameter, among others, and loads the response from that URL.
If you are trying to create an iframe DOM element, use the jQuery function to do this and append it where you want:
$('<iframe src="http://google.com" frameborder="0" scrolling="no" id="myFrame"></iframe>') .appendTo('.accordion');
or
$('<iframe>', { src: 'http://google.com', id: 'myFrame', frameborder: 0, scrolling: 'no' }).appendTo('.accordion');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With