Since these methods modify DOM, they belong to DOM manipulation category.

jquery append example : The following example appends the specified HTML to all div elements

<html>

<head>

<title></title>

<scriptsrc="jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('div').append('<b>
Tutorial</b>');

});

</script>

</head>

<bodystyle="font-family:Arial">

<divid="div1">jQuery</div>

<divid="div2">C#</div>

<divid="div3">ASP.NET</div>

</body>

</html>

Output :

jquery appendto example : The above example can be rewritten using appendTo as shown below.

<html>

<head>

<title></title>

<scriptsrc="jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('<b>
Tutorial</b>').appendTo('div');

});

</script>

</head>

<bodystyle="font-family:Arial">

<divid="div1">jQuery</div>

<divid="div2">C#</div>

<divid="div3">ASP.NET</div>

</body>

</html>

Output :

What is the difference between append and appendToBoth these methods perform the same task. The only difference is in the syntax. With append method we first specify the target elements and then the content that we want to append, where as we do the opposite with appendTo method.

jquery prepend example : The following example prepends the specified HTML to all div elements

<html>

<head>

<title></title>

<scriptsrc="jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('div').prepend('<b>Tutorial
</b>');

});

</script>

</head>

<bodystyle="font-family:Arial">

<divid="div1">jQuery</div>

<divid="div2">C#</div>

<divid="div3">ASP.NET</div>

</body>

</html>

Output :

jquery prependTo example : The above example can be rewritten using prependTo as shown below.

<html>

<head>

<title></title>

<scriptsrc="jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('<b>Tutorial
</b>').prependTo('div');

});

</script>

</head>

<bodystyle="font-family:Arial">

<divid="div1">jQuery</div>

<divid="div2">C#</div>

<divid="div3">ASP.NET</div>

</body>

</html>

Output :

What is the difference between prepend and prependToBoth these methods perform the same task. The only difference is in the syntax. With prepend method we first specify the target elements and then the content that we want to prepend, where as we do the opposite with prependTo method.

jQuery append existing element example : These methods (append, appendTo, prepend, prependTo) can also select an element on the page and insert it into another

<html>

<head>

<title></title>

<scriptsrc="jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('div').append($('#mySpan'));

});

</script>

</head>

<bodystyle="font-family:Arial">

<spanid="mySpan"> Programming</span>

<divid="div1">jQuery</div>

<divid="div2">C#</div>

<divid="div3">ASP.NET</div>

</body>

</html>

Output :

Difference between prepend and appendprepend method, inserts the specified content to the beginning of each element in the set of matched elements, where as append method inserts the specified content to the end of each element in the set of matched elements.