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 7623793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:47:44+00:00 2026-05-31T04:47:44+00:00

I often see some JavaScript libraries that are called in the head tag of

  • 0

I often see some JavaScript libraries that are called in the head tag of an html page. However, if these libs call an element in the body tag, there’ll be a response (still from the head tag). When I try to call an element from the head, there is no response – why?

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-05-31T04:47:45+00:00Added an answer on May 31, 2026 at 4:47 am

    The browser parses the html page from top to bottom, executing any <script> blocks in place as it finds them. Which means if the JavaScript attempts to access elements on the page it can only see those included higher in the page because the ones lower down have not been parsed yet.

    There are two ways to deal with this:

    1. Put your <script> block at the bottom, just before the closing </body> tag (or at least put it after the elements it needs to reference), and/or

    2. Use an onload (or, if you like jQuery, a $(document).ready()) handler.

    One way to setup an onload handler is like this:

    <head>
    <script>
       window.onload = function() {
          // this function will be called by the browser after
          // the entire page has loaded and thus code in the function
          // can access any element on the page.
       };
    </script>
    </head>
    <body>
       ... various elements ...
    </body>
    

    You may have also seen something like this:

    <body onload="someFunction();">
    

    Where someFunction() can be defined in a <script> block in the <head>. It’s basically the same thing, but it’s so 1990s to do it with an attribute in the html like that. (Actually even the window.onload() is out of date now, but it works and I don’t have time to explain the .addEventListener() method.)

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

Sidebar

Related Questions

I see a lot of code in some popular Javascript libraries that often create
I have an example of some code that I see often in websites that
often in code that uses permissions checking, i see some folks use hex 0x0001
Often I see some software and specially games that store setting in a text
I often see web applications where a program is basically some javascript objects wrapping
In Java, you often see a META-INF folder containing some meta files. What is
I see often (rewritten) URLs without ID in it, like on some wordpress installations.
I often see something like that: something.property|escape something is an object, property is it's
I often see people saying that certain software is very opinionated or that Microsoft
I often use java.lang.Integer as primary key. Here you can see some piece of

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.