Home  >  Article  >  Web Front-end  >  jQuery uses append to add multiple contents at the same time after html elements_jquery

jQuery uses append to add multiple contents at the same time after html elements_jquery

WBOY
WBOYOriginal
2016-05-16 16:07:291350browse

The example in this article describes how jQuery uses append to add multiple contents at the same time after the html element. Share it with everyone for your reference. The specific analysis is as follows:

The following code can add multiple contents after a text 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 will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn