Press "Enter" to skip to content

How to Create Elements in JavaScript

Program :

<html>

     <head>

                     <script language=”javascript”>

                                     function display()

                                                 {

                                                   a=document.getElementById(“dd”);

                                                   b=document.createElement(“input”);

                                                   b.setAttribute(“type”,”text”);

                                                   b.setAttribute(“id”,”t1″);

                                                   a.appendChild(b);

                                                   var br=document.createElement(“br”);

                                                   a.appendChild(br);

                                                 }

                                </script>

                </head>

                <body>

                    <div id=”dd”> </div> <br>

                                <input type=”button” value=”Add” onclick=”display()”/>

                </body>

</html>

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *