DEV Community

Cover image for Javascript methods
bagavath ravichandran
bagavath ravichandran

Posted on

Javascript methods

Here are the methods i learned today,

1.appendchild()
This method adds a node to the end of the list of children of
a specified parent node

   E.g: 
       <script>             
        const document.createElement("h1")
        element.innertext="Hello"
        document.body.appendchild(element)
       </script>
  In here the appendchild will create a element with h1 tag 
  with the output as "Hello".

  In writing in script we can  directly create a element in the
  body from javascript.
Enter fullscreen mode Exit fullscreen mode

2.append()

    This method inserts a set of Node objects or strings after 
    the last child of the document.
Enter fullscreen mode Exit fullscreen mode

3.Difference b/w appendchild() and append()

 append() is used to add HTML content or an element to the end 
 of an existing element while appendChild() is used to add a 
 new node element as a child to an existing node.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)