The execution position of append cannot be adjusted, and the output result can be changed.

topic description

in the following code, without changing the execution position of $("body"). Append ("bbb");, the output is changed from "bbbaaa" to" aaabbb".

.

sources of topics and their own ideas

the title comes from: Xiyanghui
my own idea of solving the problem:

related codes

/ / displays as bbbaaa after execution. It is required to change the way this code is written (the function remains the same) so that the display result becomes aaabbb. However, the execution position of $("body"). Append ("bbb"); cannot be adjusted and must be placed at the end of the main function.
$(function () {

$.get( "test.php", function( data ) {
    $( "body" ).append( "aaa" );
});
$("body").append("bbb");

});

what result do you expect? What is the error message actually seen?

Apr.22,2021

method 1:

$.get( "test.php", function( data ) {
    const content = $("body").contents();
    $( "body" ).append( "aaa" ).append(content);
});
$("body").append("bbb");

method N.

Menu