append( ) event is used to insert the content at the end of matched set of elements whereas appendTo ( ) event is used to insert matched set of elements at the end of content.Through this we can insert elements at click event, mouse-enter and mouse-leave.
As shown in below examples "hello world" is inserted at the end of matched set of element "p" in case of append event whereas in appendTo( ) matched set of element is inserted at the end of content which is "#text".
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>append demo</title>
<style>
p {
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>I would like to say: </p>
<span>this is great</span>
<div id="text"> great work</div>
<script type="text/javascript">
$(document).ready(function(){
$("p").append("<b>hello WOrld</b>");/*insert content at the end of matched set of elements.*/
$("span").appendTo("#text");/*insert matched set of element at the end of content*/
})
</script>
</body>
</html>
0 Comment(s)