UncleCoder.com

UncleCoder.com

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: 458

Edited on 08 Aug 2017



DEMO

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">
<head>
    <title></title>
</head>
<body>
    <h1> Demo for add html to div</h1>
    <button type="submit" onclick="addhtml();" > Click here</button>
    <div id="div1">
hello div1 here
        </div>
</body>
    <script type="text/javascript">
        function addhtml()
            {
                document.getElementById('div1').innerHTML = "<h3>Hello Iam in div1 </h3>"
            }
        </script>
</html>

 



Leave a Comment:


Advertisement