tags:

views:

33

answers:

1

it appears in some limited testing i've done - that if I load a document with jQuery using .ajax() and then add it to the DOM with .html(data) that any SCRIPT tag contained in the HTML document will be executed.

I'm just not sure if this is behavior I can count on? will all browsers do this? am i going to get into trouble if i'm defining any variables in that block that get overwritten later by subsequent refreshing of that part of the DOM?

Edit: Just to clarify the javascript in question is just dynamic data expressed in JSON.

+2  A: 

I would recommend separating your javascript from your markup, and using $.getScript instead, to be on the safe side, e.g.:

$.get("blah.html", function(html) {
    $.getScript("blahscript.js", function(){
      alert("Script loaded and executed.");
      $("#myDiv").html(html);
    });
});
karim79