Original: http://blog.csdn.net/woosido123/article/details/64439490 in jquery append () and prepend () is to insert content within an element (the content becomes a child element or node of the element), after () and before () are inserted outside the element (the sibling node whose content becomes an element). 1. Append () and prepend ()
<div class=‘a‘> <div class=‘b‘>b</div></div>
Use
$(‘.a‘).append($(‘.c‘));
The effect is as follows:
<div class=‘a‘> //<---you want div c to append in this <div class=‘b‘>b</div> <div class=‘c‘>c</div></div>
Same use
$(‘.a‘).prepend($(‘.c‘));
The effect is as follows:
<div class=‘a‘> <div class=‘c‘>c</div> <div class=‘b‘>b</div></div>
2. Use after () and before ()
Also use the Assumption code:
$(‘.a‘).after($(‘.c‘));
The effect is as follows:
<div class=‘a‘> <div class=‘b‘>b</div></div><div class=‘c‘>c</div>
also use before ()
$(‘.a‘).before($(‘.c‘));
The effect is as follows:
<div class=‘c‘>c</div><div class=‘a‘> <div class=‘b‘>b</div></div>
The difference between append, prepend, before, and after methods in jquery (i)