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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:25:14+00:00 2026-05-26T14:25:14+00:00

I have some code that acts as a click toggle for a menu. I

  • 0

I have some code that acts as a click toggle for a menu. I only want the code to run if the window width is under 768px, so I wrapped it in an if statement, that calculates the window width. I bound this function to the page resize event and page ready. It works some of the time but not others. Resize the results panel a few times and you’ll see what I mean…

http://jsfiddle.net/agileapricot/LyUzr/

  • 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-26T14:25:15+00:00Added an answer on May 26, 2026 at 2:25 pm

    Not the key issue, but: jQuery("#nav-btn a.togglemenu") should be jQuery("#nav a.togglemenu")

    You’ve added the click handler inside the aaMenus function, so this line:

    jQuery(window).bind("resize", aaMenus);
    

    …is running the function, and adding a new click hander, every time the window is resized. If the click handler has been added an even number of times, you’re toggling on and off at the same time, with no visible result. Even if it’s been added an odd number of times, you’re running the toggle up to hundreds of times in a row, resulting in a huge delay.

    All you need to do is take that click event handler out of your function:
    http://jsfiddle.net/mblase75/LyUzr/10/

    function aaMenus() {
        if (jQuery(window).width() > 768) { // iPad and Desktop
            /* Dropdown Menu */
            jQuery("ul#menu").addClass("dropdown").removeClass("toggle").show();
            jQuery("a.togglemenu").hide();
    
            //.. Drop down function will go here later
        } else { // Mobiles
            /* Toggle menu */
            jQuery("ul#menu").addClass("toggle").removeClass("dropdown").hide();
            jQuery("a.togglemenu").show();
        }
    }
    
    jQuery(window).bind("resize", aaMenus);
    
    jQuery(document).ready(function() {
        jQuery("#nav a.togglemenu").click(function() {
            jQuery("ul.toggle").toggle();
        });
        aaMenus();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some image processing Java code in Android that acts upon two large
I have some code which works nicely and acts like a menu appearing when
I have some Javascript code that acts on an pixel array defined like so:
I have some code that uses a form.submit() to open up another window when
I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general
I have some code that effectively does this : File file = new File(C:\\Program

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.