Press "Enter" to skip to content

How to Remove 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);

                                  }

                                  function removeElement()

                                  {

                                  a=document.getElementById(“dd”);

                                  b=document.getElementById(“t1”);

                                  a.removeChild(b);

                                  }

                  </script>

                </head>

                <body>

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

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

                   <input type=”button” value=”remove” onclick=”removeElement()”/>

                </body>

</html>

Be First to Comment

    Leave a Reply

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