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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:45:20+00:00 2026-06-04T13:45:20+00:00

I am attempting to create a mobile website from my ‘desktop’ site through CSS

  • 0

I am attempting to create a mobile website from my ‘desktop’ site through CSS media queries.

I have a simple drop down menu(desktop) that can transform into a pushdown menu(mobile). the css is loaded for the desktop at anything over a browser width of 768px and the mobile push down menu is loaded at anything under 767px.

Problem is the pushdown menu requires a js file to function properly. The js file forces the div that contains the menu to be hidden. So upto 767px browser width the pushdown works fine, at 768px the desktop nav is not visible.

I am new to JavaScript and Jquery, but I have tried to get this to operate effectively using my minimal knowledge. I need it to be as simple as possible as the site must be minimal as possible.

At the moment this is the closest I have got it to functioning properly:

function hideDiv(){
    if ($(window).width() < 768) {

        $(".togglebox").hide();

    }else{

        $(".togglebox").show();

    }

}

//run on document load and on window resize
$(document).ready(function () {

    //on load
    hideDiv();

    //on resize
    $(window).resize(function(){
        hideDiv();
    });

});


$(document).ready(function(){

    $(".togglebox").hide();

    $("h1").click(function(){

    $(this).next(".togglebox").slideToggle("slow");
    return true;
    });
});

Notes:

The togglebox div needs to be hidden for the pushdown menu to work, however the same div needs to be visible at over 768px width in order for the desktop navigation to be visible.

The above code makes it work fine, however when I type in the page url no navigation is present until I attempt to resize the browser width. I am aware I have two (document).ready function’s and maybe this is the problem, but I’ve tried playing with the code but I haven’t had any luck. There must be a simple solution that I am overlooking?

I thought maybe executing the pushdown menu functions at anything upto 767px width only, then anything above that to simply show the togglebox div.

  • 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-04T13:45:21+00:00Added an answer on June 4, 2026 at 1:45 pm

    Your code doesn’t work when the page first loads because you are always hiding it when the page first loads. Instead of always hiding it when the page first loads, you just need to call the function you already have hideDiv() and it will determine whether it should be initially visible or not. Change your code to this (removing the .hide() line and letting the one call to hideDiv() do its natural job):

    function hideDiv(){
        if ($(window).width() < 768) {
            $(".togglebox").hide();
        }else{
            $(".togglebox").show();
        }
    }
    
    //run on document load and on window resize
    $(document).ready(function () {
        //on load
        hideDiv();
    
        //on resize
        $(window).resize(function(){
            hideDiv();
        });
    });
    
    
    $(document).ready(function(){
        $("h1").click(function(){
            $(this).next(".togglebox").slideToggle("slow");
            return true;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create a gallery/gridview that is loaded with images from a specific
I'm attempting to create a complex div structure using CSS. I want it to
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in
I am attempting to create a website utilizing PHP as the driving power behind
I am attempting to create a simple base class and another class that inherits
I'm attempting to create a column in css that is 100% height of the
I'm attempting to create an app to pull the sqlite data from a preexisting
I am attempting to create a custom tableview where I have a list of
I am attempting to create a small application to collect data received from an
I am attempting to create new membership users in an Ektron CMS400.NET-based website by

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.