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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.