Free programming examples and instructions

Add html tags to div

Code, demo for append html tags to a div using javascript

by Athil

Posted on 13 May 2017 Category: Javascript Views: 1017

Edited on 25 Jul 2018


Hi, here I am going to show how to add HTML tags inside a div using javascript.

  document.getElementById('div1').innerHTML = "<h3>Hello Iam in div1 </h3>";

This code changes the html tags inside div1 with h3 "Hello Iam in div1"


Full example

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <h1> Demo for add html to div</h1>
    <button type="submit" onclick="addhtml();" > Click here</button>
    <div id="div1">
hello div1 here
    <script type="text/javascript">
        function addhtml()
                document.getElementById('div1').innerHTML = "<h3>Hello Iam in div1 </h3>"


Leave a Comment: