1

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

Markus
  • 3,225
  • 6
  • 35
  • 47
Mr King
  • 21
  • 5

3 Answers3

2

The script is stripped out of the HTML loaded.

From the jQuery docs about load() (emphasis added)

http://api.jquery.com/load/

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" );

mrk
  • 4,999
  • 3
  • 27
  • 42
1

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>
Mr King
  • 21
  • 5
0

Try this.

$("#register_form").load("test_test.php #register_rules",function(){
    $.getScript("jquerycode.js"); 
});
Md Nazmoon Noor
  • 3,187
  • 1
  • 24
  • 30