jQuery append() append created HTML element

Description

jQuery append() append created HTML element

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from www. ja  v  a2s. c o  m*/
<script>
function appendText() {
  var txt1 = "<p>Text.</p>";       
  var txt2 = $("<p></p>").text("Text."); 
  var txt3 = document.createElement("p");
  txt3.innerHTML = "Text.";      
  $("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>



PreviousNext

Related