UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Add Html tags to a div - Javascript

Demo and code for how to add html tags to div in javascript.

by Athil


Posted on 27 Jul 2018 Category: Javascript Views: 5726


Here I am going to show how to add HTML tags to div using javascript.

DEMO 

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

Where 'div1' is controlid of the div and we are adding "<h3>Hello Iam in div1 </h3>" to div1

Full Demo Code

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


Click here to register

Popular articles