Reputation: 21
In the header of the first page
<script type="text/javascript">
$(document).ready(function(){
$("#register_reg").click(function(){
$("#register_form").load("test_test.php #register_rules");
});
});
</script>
In the content of the ID #register_rules in the second file (test_test.php) there are this line
<script type="text/javascript" src="jquerycode.js"></script>
The probleme is, in the fist page, when i click the link (ID #register_reg) the line script not added in the ID #register_form
So, how I can add the content of the ID #register_rules with here script in the ID #register_form
Upvotes: 1
Views: 1625
Reputation: 21
this is the correct code
<script type="text/javascript">
$(document).ready(function(){
$("#register_reg").click(function(){
$("#register_form").load("test_test.php #register_rules", function() {
$("#register_form").append("<script type='text/javascript' src='jquerycode.js'></" + "script>");
});
});
});
</script>
Upvotes: 1
Reputation: 3307
Try this.
$("#register_form").load("test_test.php #register_rules",function(){
$.getScript("jquerycode.js");
});
Upvotes: 0
Reputation: 5117
The script is stripped out of the HTML loaded.
From the jQuery docs about load() (emphasis added)
Script Execution
When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed. An example of both cases can be seen below:
Here, any JavaScript loaded into #a as a part of the document will successfully execute.
1 $( "#a" ).load( "article.html" ); However, in the following case, script blocks in the document being loaded into #b are stripped out and not executed:
1 $( "#b" ).load( "article.html #target" );
Upvotes: 2