jquery ajax html response change 1.3.2 vs 1.4.2 (aka where is my script tag?)

Posted by cmroanirgo on Stack Overflow See other posts from Stack Overflow or by cmroanirgo
Published on 2010-03-23T23:50:47Z Indexed on 2010/03/23 23:53 UTC
Read the original article Hit count: 323

I've been using jquery 1.3.2 to pull snippets of html (including script) from a server. A typical response might be:

<div id="content"><div id="inner">...

<script type=...> alert("hello world");</script>

<p>Hello World</p>

</div></div>

I've been using the query .get function:

$.get($(this).attr("href"), function(response) {
    $("#inner").replaceWith($("#inner", response));
        });

And everything is fine and works as expected: the returned html snippets get loaded into the DOM and the scripts run.

When I use 1.4.2 however, I notice that the script tags have been removed and no longer run.

Stepping into the newer jquery codebase yields the lines of code (line 4498) :

ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );

which seems to be the culprit 'removing' the script from its happy resting place as part of the selector process. But it doesn't help me in injecting exactly what i want into the DOM.

Any idea why jquery is doing this? More importantly, how can I go about fixing this so that my scripts run?

© Stack Overflow or respective owner

Related posts about jquery-ajax

Related posts about jQuery