| Viewed 51 times

How to append HTML in javascript


How to append HTML in javascript

1 Answer
Mohammad Qandeel
Answered
6

Using appendChild() function  

Example

<div id="target_DIV"></div>

<button onclick="appendFunction()">appendChild</button>

<script>
function appendFunction() {
  var create_p = document.createElement("P");
  create_p.innerHTML = "New paragraph.";
  document.getElementById("target_DIV").appendChild(create_p);
}
</script>

When you click the button the appendFunction will start and create a P element with some text then append it to target_DIV.