I have an iframe and I load some html+javascript into it dynamically with the following code:
var allMyCode = "<div id='test'>html code</div> <script type='text/javascript'>alert(document.getElementById('test').innerHTML);<\/script>";
$("#myFrame").contents().find("body").html(allMyCode);
The problem is I would like this to alert the text 'html code' but it actually gets the html in the div in the parent with the id of 'test', so it's not referencing itself. I've shown this in this fiddle: http://jsfiddle.net/BNG4n/
Why is it doing this, how can I make the JavaScript run on its own scope!?