Load JS script inside HTML
Hello,
I want to change from 1.3.2 to 1.4.2 but I block facing unexpected behavior :
The code <script type="text/javascript"></script> is filter when I use $() [http://api.jquery.com/jQuery/] with a context. The javascript inside the HTML is not executed.
An example :
Page which called another with Ajax
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
$.get("load.aspx", function(data) {
alert("Data Loaded: " + data);
var content = $("#content", data).html();
$("#customContainer").html(content);
alert(data);
alert(content);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>test jquery</h1>
<div id="customContainer"></div>
<hr />
<div id="result"></div>
</div>
</form>
</body>
</html>
Page which is called by the first one :
<div>
<strong>du html</strong>
<p id="content">
<span style="color: Red">toto</span>
<br />
<script type="text/javascript">
alert("titi");
</script>
<span>tutu</span>
</p>
</div>
The line var content = $("#content", data).html(); delete the JS code.
This code works great with jQuery 1.3.2
I can see the code JS disappear with the alerts :
alert(data); // I have all the code of the page with the JS inside the HTML
alert(content); // I want only the content of the div "content" with the JS, but the javascript disappear
Anyone has an idea ?
thanks