How to use DOM Object CreateElement in JavaScript

In this article I am going to explain about DOM Object CreateElement() Method in JavaScript.
  • 1769

JavaScript DOM Object CreateElement() Method

JavaScript CreateElement() method use for cerate a new element node with specified name.

Syntax

var ss=Document.CreateElement("Button")

Example // In this example when you will click on button then a new button will be created.

<html>

<head>

    <script type="text/javascript">

 

        function myfun() {

            var bb = document.createElement("Button");

            var tt = document.createTextNode("New Button");

            bb.appendChild(tt);

            document.body.appendChild(bb);

        };

 

    </script>

</head>

<body>

    <p>

        Create button for create new element</p>

    <button onclick="myfun()">

        click me</button>

</body>

</html>

 

Output

 

Before Click button


createelemnt1.gif

 

After click button

createeleemnt2.gif

 

You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.