Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:13:25+00:00 2026-06-08T07:13:25+00:00

I am using javascript from few days. And i am confusing between getElementById and

  • 0

I am using javascript from few days. And i am confusing between getElementById and createElement.

THANKS IN ADVANCE

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:13:27+00:00Added an answer on June 8, 2026 at 7:13 am

    The main difference is that getElementById will get an element from the DOM by it’s ID attribute, and createElement will create an entirely new DOM element.

    Let’s say you had a page with the following HTML:

    <!doctype html>
    
    <html>
      <head>
      </head>
    
      <body>
        <div>Hello, World!</div>
        <div id="message">What a nice day!</div>
      </body>
    </html>
    

    And then you had some JavaScript code like so:

    document.getElementById("message")
    

    You will retrieve the <div> element that has an id attribute of "message".

    Now, let’s say you wanted to add a new element to your HTML page, then you’d use the createElement function.

    var newEl = document.createElement("div")
    

    Of course, from the example, we are also storing the new element in a variable called newEl.

    Now, to actually append the new element, we’d have to call appendChild on any DOM element. For the sake of simplicity, we’re going to simply append to the <body> tag.

    document.body.appendChild(newEl)
    

    Now, your page should (at least in the mind of the browser) look like so:

    <!doctype html>
    
    <html>
      <head>
      </head>
    
      <body>
        <div>Hello, World!</div>
        <div id="message">What a nice day!</div>
        <div></div>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a script from http://www.yourinspirationweb.com/en/jquery-how-to-create-a-news-ticker-with-just-a-few-javascript-lines/ which is a great newsticker, designed to
I've changed a few pages from using generic JavaScript that sets a CSS style
I'm trying to save the e-mail body and its attachments from javascript using a
I created a WCF rest service, then called that from javascript using ajax. Now
Using Javascript how would I remove any number of ../ from a relative path?
I'm using the JavaScript mongodb driver from nodejs. I want to do this query
I am using some pre-written JavaScript from polldaddy. They have a JavaScript option which,
I want to retrieve HTML and Javascript from the same page using AJAX calls.
I'm using the combination of json_encode (PHP) and JSON.parser (Javascript from json.org) for passing
Is it possible for a web page using Javascript to get data from another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.