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

1

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

0

Try this.

$("#register_form").load("test_test.php #register_rules",function(){
    $.getScript("jquerycode.js"); 
});

1 Comment

not working, the function "append" working verry well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.