jQuery USES append's method of adding more than one thing at a time after an html element

  • 2020-05-19 04:15:19
  • OfStack

The example in this article shows how jQuery USES append to add multiple items after an html element. Share with you for your reference. The specific analysis is as follows:

The following code allows you to add more than one piece of text behind a paragraph at the same time


<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
function appendText()
{
var txt1="<p>Text.</p>"; // Create text with HTML
var txt2=$("<p></p>").text("Text."); // Create text with jQuery
var txt3=document.createElement("p");
txt3.innerHTML="Text."; // Create text with DOM
$("body").append(txt1,txt2,txt3); // Append new elements
}
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button onclick="appendText()">Append text</button>
</body>
</html>

I hope this article has been helpful to your jQuery programming.


Related articles: