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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:40:20+00:00 2026-05-27T05:40:20+00:00

I have the following jQuery code: $(‘#menu .selected’).removeClass(‘selected’); $(‘#homel’).addClass(‘selected’); $(‘#home’).slideDown(150, function() { $(‘#public’).slideUp(200); $(‘#login’).slideUp(200);

  • 0

I have the following jQuery code:

$('#menu .selected').removeClass('selected');
      $('#homel').addClass('selected');
      $('#home').slideDown(150, function() {
        $('#public').slideUp(200);
        $('#login').slideUp(200);
        $('#faq').slideUp(200);

      });

Which, as you can guess, hides and shows div boxes. In that example #homel is the Home link, and #home is the home div. This looks ok, but if I want to add a new box, for example, #registerI have to add here and on every other box code (#public, #login and #faq) the code: $('#register').slideUp(200);
Is there any way that can be simplified and made generic for all?

EDIT: jsFiddle link for the example here

  • 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-27T05:40:21+00:00Added an answer on May 27, 2026 at 5:40 am

    Here is a different solution. I gave all h3 divs a common class and select them with one selector. This way it’s you don’t have to change your code everytime you add another div. There is also a function for slideUp. Now all routes can use same function, no need for lots of anonymous functions.

    This is the final result;

    HTML

    <div id="menu">
        <a href="./#/home" class="selected" id="homel">Home</a> <a href="./#/public" id="publicl">Public</a> <a href="./#/users/login" id="loginl">Login</a> <a href="./#/faq" id="faql">FAQ</a>
    </div>
    <div id="content">
        <div id="home" class="h3div">
            <h3>Welcome</h3>
        </div>
        <div id="public"class="h3div">
            <h3>Public</h3>
        </div>
        <div id="login"class="h3div">
            <h3>Login</h3>
        </div>
        <div id="register"class="h3div">
            <h3>Register</h3>
        </div>
        <div id="faq" class="h3div">
            <h3>Frequently Asked Questions</h3>
        </div>
    </div>
    

    Javascript

    $(document).ready(function() {
        $.routes({
            '/': function() {
                $('#home').slideDown(200);
            },
            '/home': function() {
                menuSlideUpDown('home');
            },
            '/public': function() {
                menuSlideUpDown('public');
            },
            '/users/:what': function(params) {
                if (params.what == "login") {
                    menuSlideUpDown('login');
                } else if (params.what == "register") {
                    menuSlideUpDown('login');
                }
            },
            '/faq': function() {
                menuSlideUpDown('faq');
            }
        });
    });
    
    function menuSlideUpDown(item) {
        $('#menu a').removeClass('selected').filter('#' + item + 'l').addClass('selected');
        $('#' + item).slideDown(150, function() {
            $('.h3div').not(this).slideUp(150);
        });
    }
    

    And working example of final result is here.

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

Sidebar

Related Questions

I have the following jQuery code: $(ul.menu li a).click(function() { $(ul.menu li a).removeClass(currentMenu); $(this).addClass(currentMenu);
I have the following JQuery Code concerning my tabs : $(#onglet>ul>li).click(function(){ $(#onglet ul li).removeClass('Selectionne').addClass(OngletPrincipal);
I have the following jQuery code $(#dropdown).hover(function() { $(this).stop(true,true).fadeTo('fast',1); $(#options).stop(true,true).slideDown(); }, function() { $(this).delay(1000).stop(true,true).fadeTo('fast',0.1);
I have the following jquery-code: <script type=text/javascript> $(document).ready(function() { $ ('ul.image-list li:even').addClass ('even'); $
I have the following jQuery Code: $(#menu span).click(function() { var url = this.getAttribute(data-url); var
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have problems with the following bit of javascript/jquery code: this.droppable = function(){ $('.imageWindow
i have the following jquery code to format a html table. $(.jtable td).each(function() {
i have the following jquery code: $(document).ready(function() { $('.restrictiveOptions input[type!=checkbox], .restrictiveOptions select').change(function() { //
I have the following jQuery code which all works fine: $(#sidebar .m3, #sidebar .m5).toggle(function()

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.