Add HTML, jQuery DOM and Javascript DOM - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:append

Description

Add HTML, jQuery DOM and Javascript DOM

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
function appendText() {/*w w w  .  jav  a2 s . c  om*/
    var txt1 = "<p>plain html.</p>";              // Create text with HTML
    var txt2 = $("<p></p>").text("jQuery dom");  // Create text with jQuery
    var txt3 = document.createElement("p");
    txt3.innerHTML = "Javacript DOM.";               // 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>

Related Tutorials