We can add html dynamically to our website using jQuery.
We use to add html dynamically like when we want on some click function or we want to some other event to add boxes and any other thing.
We can use function to add
function appendText() {
var txt1 = "<p>Text.</p>"; // Create element with HTML
var txt2 = $("<p></p>").text("Text."); // Create with jQuery
var txt3 = document.createElement("p"); // Create with DOM
txt3.innerHTML = "Text.";
$("p").append(txt1, txt2, txt3); // Append the new elements
}
We can also use before() and after() to append or remove before or after something.
This can be used to remove the html
function removeText() {
txt3.innerHTML = "Text.";
$("p").remove(txt1, txt2, txt3); // remove the elements
}
0 Comment(s)