How to insert dynamically iframe in a div with jQuery?
$(document).ready(function() {
$("div").html("<iframe src='http://google.com'><iframe>");
});
This doesn't work.
How to insert dynamically iframe in a div with jQuery?
$(document).ready(function() {
$("div").html("<iframe src='http://google.com'><iframe>");
});
This doesn't work.
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.
The actual jquery code looks fine, you may not be referencing the div correctly i.e.
#div - would be an element with the id "div"
.div - would be an element with the class "div"
It works, I just tested it, what you might need is give jquery the id/class of the div you want to insert the iframe
eg. (id)
$("#myDiv").html("<iframe src='http://google.com'></iframe>");
eg. (class)
$(".myDiv").html("<iframe src='http://google.com'></iframe>");
Yes. It is working fine.
Check here : http://jsbin.com/arolo3/2/edit
You should close the iframe tag. It might be the issue.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$("#frameDiv").html("<iframe src='http://google.com'></iframe>");
});
</script>
<p>An IFrame should appear here</p>
<div id="frameDiv" style="width: 400px; height: 400px;"></div>
</body>