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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:48:06+00:00 2026-06-09T13:48:06+00:00

Getting TypeError: document.getElementById(free_shipping) is null This is what im trying — I just want

  • 0

Getting TypeError: document.getElementById("free_shipping") is null

This is what im trying —

I just want to make sure that these two particular div show only only my home page . but im getting this error however alerts are working. Let me know if im missing something.

Can i made this code even better as i only have to use JAVACRIPTin this case.

JS CODE

<script type="text/javascript">
var myaddr = location.host;
if(myaddr  == "abc.xy.com")
{
document.getElementById('free_shipping').style.display="visible"; 
document.getElementById('sale').style.display="visible"; 
//alert("I am in if");
}
else{
document.getElementById('free_shipping').style.display="none"; 
document.getElementById('sale').style.display="none"; 
//alert("I am in else");
}
</script>

HTML CODE

    <!--####### Free Shipping Start ##############-->
    <div id="free_shipping">
    </div>
    <!--Free Shipping End-->
    <!--####### Sale Start ####### -->
    <div id="sale">
    </div>
    <!--Sale End-->

CSS CODE

    #free_shipping
    {
    background: url("../images/template/swap_free_shipping.jpg") no-repeat scroll 0 0 transparent;
    height: 112px;
    left: -57px;
    position: relative;
    top: 256px;
    width: 62px;  
    }
    #sale
    {
    background: url("../images/template/swap_sale.jpg") no-repeat scroll 0 0 transparent;
    left: -55px;
    position: relative;
    top: 384px;
    width: 59px;
    height: 79px;

}
  • 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-09T13:48:06+00:00Added an answer on June 9, 2026 at 1:48 pm

    If your <script> is in the <head></head> section of your website, then it will start to execute before the page has loaded, and therefore free_shipping and sale will not exist in the DOM.

    Try doing the following, which will make your code happen once the page has finished loading…

    <script type="text/javascript">
      window.onload = function() {
        var myaddr = location.host;
        if(myaddr  == "abc.xy.com")
        {
          document.getElementById('free_shipping').style.display="visible"; 
          document.getElementById('sale').style.display="visible"; 
          //alert("I am in if");
        }
        else{
          document.getElementById('free_shipping').style.display="none"; 
          document.getElementById('sale').style.display="none"; 
          //alert("I am in else");
        }
     }
    </script>
    

    This can also be done using the jquery library, but my knowledge of it is exceedingly limited.

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

Sidebar

Related Questions

I'm getting TypeError: coercing to Unicode: need string or buffer, int found This is
I'm getting this error: uncaught TypeError: Object [object Object] has no method 'on' at
I'm trying to use defmacro in ClojureScript, but I'm getting a console error: TypeError:
I'm trying to pickle a big class and getting TypeError: can't pickle module objects
I'm getting a TypeError: cannot concatenate 'str' and 'list' objects. I'm trying to pass
I'm getting this error: TypeError: datetime.datetime(2012, 2, 12, 0, 47, 6, 542000) is not
Hey peepz! I have this footer image, that I want to align to the
Here is the error that I am getting in Google Chrome: Uncaught TypeError: Object
I am getting this error- TypeError: Error #1009: Cannot access a property or method
I keep getting this error: TypeError: Error #1006: setSize is not a function. at

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.