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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:13:24+00:00 2026-06-10T05:13:24+00:00

I am wondering why my last else if statement never gets executed. I am

  • 0

I am wondering why my last else if statement never gets executed. I am trying to do this:

$(document).ready(function() {
    function checkWidth() {
        var windowSize = $(window).width();

        if (windowSize <= 479) {
            console.log("screen width is less than 480");
        }
        else if (windowSize = 480 && windowSize <= 719) {
            console.log("screen width is less than 720 but greater than or equal to 480");
        }
        else if (windowSize = 720 && windowSize <= 959) {
            console.log("screen width is less than 960 but greater than or equal to 720");
        }
        else if (windowSize >= 960) {
            console.log("screen width is greater than or equal to 960");
        }
    }

    // Execute on load
    checkWidth();
    // Bind event listener
    $(window).resize(checkWidth);
});​

Everything gets logged in the console except for the last else if. What am I doing wrong?

Thanks,

UPDATE:

For anyone still interested, I highly recommend the enquire.js plugin:

http://wicky.nillia.ms/enquire.js/

Hands down best approach I’ve found to recognizing media queries in JS.

  • 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-10T05:13:25+00:00Added an answer on June 10, 2026 at 5:13 am

    You are missing a couple >= in your code, and windowSize is not being compared but assigned a new value as a result of statements like windowSize = 480. Try this version instead:

    $(document).ready(function() {
        function checkWidth() {
            var windowSize = $(window).width();
    
            if (windowSize <= 479) {
                console.log("screen width is less than 480");
            }
            else if (windowSize <= 719) {
                console.log("screen width is less than 720 but greater than or equal to 480");
            }
            else if (windowSize <= 959) {
                console.log("screen width is less than 960 but greater than or equal to 720");
            }
            else if (windowSize >= 960) {
                console.log("screen width is greater than or equal to 960");
            }
        }
    
        // Execute on load
        checkWidth();
        // Bind event listener
        $(window).resize(checkWidth);
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im wondering if anyone else has come across this problem when designing websites. Basically
Hey guys I was wondering why my last script in this file isn't working
I've been struggling with this for the last hour or so, wondering if some
I have never seen this issue before, its very strange. Just wondering if anyone
I'm been wrestling with this issue for the last few days. Wondering if anyone
I was wondering about the last constructor for std::string mentioned here . It says:
Im wondering if the way i use to retrieve the id of the last
I'm just wondering how I could display my last 200 mysql entries in php
Wondering what the best / good way of doing this would be in jQuery.
I'm wondering if there's a way to dump all of the values of $this->session->userdata()

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.