Hello Readers,
appendTo() is the jquery method which is used to insert the any HTML elements at the end of the given selector as a parameter into the appendTo() method.
Syntax :
$(content).appendTo(selector)
Parameters :
content : it is a required parameter which specifies the content to insert at the end.
selector : it is also a required parameter which specifies on which elements to append the content to.
Code Example :
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("<span>Hello World!</span>").appendTo("p");
});
});
</script>
</head>
<body>
<button>Insert element</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
In the above code, we use the button on click of button append the HTML string to the selector p tag at the end.
0 Comment(s)