<p class='a'> //<---you want p c to append in this <p class='b'>b</p> </p>
is used
$('.a').append($('.c'));
The effect is as follows:
<p class='a'> //<---you want p c to append in this <p class='b'>b</p> <p class='c'>c</p> </p>
Similarly use
$('.a').prepend($('.c'));
The effect is as follows:
<p class='a'> //<---you want p c to append in this <p class='c'>c</p> <p class='b'>b</p> </p>
Also use the hypothetical code:
$('.a').after($('.c'));
The effect is as follows:
<p class='a'> <p class='b'>b</p></p><p class='c'>c</p>
Also use before()
$('.a').before($('.c'));
The effect is as follows:
<p class='c'>c</p><p class='a'> <p class='b'>b</p></p>
<p class='a'> //<---you want p c to append in this <p class='b'>b</p> </p>
$('.a').append($('.c'));
<p class='a'> //<---you want p c to append in this <p class='b'>b</p> <p class='c'>c</p> </p>
$('.a').prepend($('.c'));
<p class='a'> //<---you want p c to append in this <p class='c'>c</p> <p class='b'>b</p> </p>
$('.a').after($('.c'));
<p class='a'> <p class='b'>b</p></p><p class='c'>c</p>
$('.a').before($('.c'));
<p class='c'>c</p><p class='a'> <p class='b'>b</p></p>
The above is the detailed content of The difference between append, prepend, before and after methods in jquery. For more information, please follow other related articles on the PHP Chinese website!