Dail
Dail

Reputation: 4608

Jquery .html() seems not update JS code

I load a template from an ajax call(and I put that content inside a div using .html()). This template has and some divs.

The problem is that I receive the correct JS from that call, but it seems that .html() does not update the <script>. I have:

<div id="val">
   <script>....</script>
</div>

when I do: $('#val').html(contentFromAJAX), the JS is not loaded correctly. How can i do?

EDIT: with "not loaded correctly", I mean that the previous <script> inside that div remain there, .html() seems do not change it.

Upvotes: 0

Views: 90

Answers (1)

xdazz
xdazz

Reputation: 160973

Set the dataType of your ajax call: dataType: "script"

Or use the jQuery.getScript()

Upvotes: 1

Related Questions