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

  • Home
  • SEARCH
  • 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 8928545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:27:45+00:00 2026-06-15T08:27:45+00:00

My HTML includes the code: <div id=msg></div> In its body. In the head section

  • 0

My HTML includes the code:

<div id="msg"></div>

In its body.

In the head section I then have:

var msg = document.getElementByID("msg");

But when I then call within a function:

msg.innerHTML = "test";

It returns an error stating that msg is null. What should I do?

  • 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-15T08:27:46+00:00Added an answer on June 15, 2026 at 8:27 am

    Firstly, you have to consider that JavaScript is case sensitive language, so you should use getElementById (note case of last letter). Next, if you get element by id, you should pass ID as an argument (not a tag name):

    var msg = document.getElementById("msg");
    

    You can read more information about this method in MDN:

    • https://developer.mozilla.org/en-US/docs/DOM/document.getElementById

    Also, one important note is to use this code when the markup is fully loaded, i.e. when your msg element is “visible” for JavaScript. In order to achieve this, one option is to put your <script> tag (with corresponding JavaScript code) to the end of HTML right before </body>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code <html> <include jquery> <script> function crea() { var html =
in below code; it gets a content of a div includes html codes, and
I have a dynamic webpage that includes an iFrame where external html code is
I have the following code which loads some html (which includes anchors) into a
I have HTML which includes scripts in following order <script src=../static/js/jquery.js type=text/javascript> <script src=../static/js/bootstrap.js
I have a HTML that includes a Javascript file. This script contains a special
I have a text file of HTML that includes the following marker set for
I have a PHP script (index.php) that includes an index.html file in a sub-directory
Within my HTML, I have a php script that includes a file. At that
function updateOption(selection, option) { jQuery('body,html').animate({ scrollTop: jQuery(#msg).offset().top }, 800); jQuery('.'+selection).each(function() { jQuery(img.+selection).removeClass(optionSelected); }); jQuery.ajax({

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.