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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:06:17+00:00 2026-05-30T23:06:17+00:00

I just started on my first JavaScript project which is a small script to

  • 0

I just started on my first JavaScript project which is a small script to detect the browser window size, and if it is below 1100px then the div quick will not be shown.

Here is my code:

<Script language="Javascript">
  function toggle(id) {
    var browserwidth =  window.screen.width;
    if (browserwidth <= 1100) {
      document.getElementByID(quick).style.display = 'none';
    } else {
      document.getElementById(quick).style.display = 'block';
    }
  }
</script>

but I cannot figure out for the life of me my it does not work. I am fully aware that css @media could do what I am trying to do but it would not work for the current project I am working on.

  • 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-30T23:06:18+00:00Added an answer on May 30, 2026 at 11:06 pm

    You have no variable called quick. We assume that should be a quoted string 'quick':

    if (browserwidth <= 1100) {
      document.getElementByID('quick').style.display = 'none';
    } else {
      document.getElementById('quick').style.display = 'block';
    }
    

    For debugging JavaScript, the Firefox extension Firebug is recommended, or Chrome & Safari’s Developer Tools console. When you run the script, errors will be printed to the console and although they won’t usually tell you the exact problem, they’ll usually identify where the problem occurs.

    Update

    After seeing the implementation on pastebin, your code is not executing because, well, you aren’t executing it. Your function has been correctly defined but is not being triggered by any event. Bind it to a button onclick or window.onresize to test its functionality:

    <button onclick="toggle('quick');">Click to toggle</button>
    

    I have also used the input parameter of your function (id) to dynamically choose the div, rather than hard-coding 'quick':

    function toggle(id) {
      var browserwidth =  window.screen.width;
      if (browserwidth <= 1100) {
        // Use id here...
        document.getElementByID(id).style.display = 'none';
      } else {
        document.getElementById(id).style.display = 'block';
      }
    }
    // For completeness, additional info ported in from comments:
    
    // Function to call toggle()
    function init() {
      toggle("quick");
    } 
    // Attach it to the window.onload event so it fires when the page load completes
    window.onload = init;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started looking at the new FIRST Robotics Java SDK, which includes project
When I first started with Javascript, I usually just put whatever I needed into
I just started my first Mercurial project. I did a 'cd' into my source
So I just started my first rails project yesterday. I had two many-to-many (has_and_belongs_to_many)
I just started working on my first Visual Studio project, and I imported all
Just started my first WCF rest project and would like some help on what
I have just started my first project on GeoDjango. As a matter of fact,
Hey, I've just started learning JavaScript and I'm making a little script that generates
Just started my first MVC 2.0 .net application. And I set up some default
I've just started my first development job for a reasonably sized company that has

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.