Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  165] [ 5]  / answers: 1 / hits: 60441  / 14 Years ago, tue, july 13, 2010, 12:00:00

How do I dynamically insert an iframe in a div using jQuery?



$(document).ready(function() {
$(div).html(<iframe src='http://google.com'><iframe>);
});


I tried the above code, but it doesn't work.


More From » jquery

 Answers
65

What you have works: http://jsfiddle.net/cUSVj/



Though keep in mind you can't do much with it after it's created if it's in not in the same domain, this is due to restrictions in place per the same-origin policy.



Edit: I was closing the tag thinking it was a paste error, you are indeed missing a / in your </iframe> closing tag...this will/won't work depending on how generous the browser is. Make sure to close it correctly so your HTML is valid, otherwise you'll have cross-browser issues, if it works to begin with.


[#96248] Saturday, July 10, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
koltenb

Total Points: 276
Total Questions: 92
Total Answers: 101

Location: North Korea
Member since Fri, Nov 4, 2022
2 Years ago
;