DEV Community

Cover image for Javascript methods
bagavath ravichandran
bagavath ravichandran

Posted on

1

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

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay