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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:28:18+00:00 2026-05-12T10:28:18+00:00

Imagine i have this HTML snippet 4 times over for four different sections of

  • 0

Imagine i have this HTML snippet 4 times over for four different sections of menu nav

<ul class="navigation">
  <li class="nav-Mens"><a href="#">Mens</a></li>
  <li class="nav-Womens"><a href="#">Womens</a></li>
  <li class="nav-Kids"><a href="#">Kids</a></li>
  <li class="nav-Gear"><a href="#">Gear</a></li>
</ul>
   <div id="Gear">
  <ul class="Gear">
    <table width="300" border="0" cellspacing="5" cellpadding="0">
      <tbody><div style="background-color:#333; color:#000">SHOP GEAR</div>
      <tr>
        <td><a href="#"><b>Snow</b></a>
        <p></p>
          <li><a href="#">Bags</a></li></td>
        <td><a href="#"><b>Surf</b></a>
        <p></p>
          <li><a href="#">Towels</a></li></td>
      </tr>
    </tbody></table>
  </ul>
</div>

and my jquery looks like this

// JavaScript Document
$(document).ready(function() {

//Mens
$("li.nav-Mens").mouseover(function() {
    clearTimeout(timeout);
    $('#Mens').show();
    $('#Womens').hide();
    $('#Kids').hide();
    $('#Gear').hide();
});
var timeout;
$("li.nav-Mens").mouseout(function() {
    timeout = setTimeout('hideMens()', 1000);
});
$('#Mens').mouseover(function() {
    clearTimeout(timeout);
});
$('#Mens').mouseout(function() {
    timeout = setTimeout('hideMens()', 1000);
});

//Womens
$("li.nav-Womens").mouseover(function() {
    clearTimeout(timeout);
    $('#Womens').show();
    $('#Mens').hide();
    $('#Kids').hide();
    $('#Gear').hide();
});
var timeout;
$("li.nav-Womens").mouseout(function() {
    timeout = setTimeout('hideWomens()', 1000);
});
$('#Womens').mouseover(function() {
    clearTimeout(timeout);
});
$('#Womens').mouseout(function() {
    timeout = setTimeout('hideWomens()', 1000);
});

//Kids
$("li.nav-Kids").mouseover(function() {
    clearTimeout(timeout);
    $('#Womens').hide();
    $('#Mens').hide();
    $('#Kids').show();
    $('#Gear').hide();
});
var timeout;
$("li.nav-Kids").mouseout(function() {
    timeout = setTimeout('hideKids()', 1000);
});
$('#Kids').mouseover(function() {
    clearTimeout(timeout);
});
$('#Kids').mouseout(function() {
    timeout = setTimeout('hideKids()', 1000);
});

//Gear
$("li.nav-Gear").mouseover(function() {
    clearTimeout(timeout);
    $('#Womens').hide();
    $('#Mens').hide();
    $('#Kids').hide();
    $('#Gear').show();
});
var timeout;
$("li.nav-Gear").mouseout(function() {
    timeout = setTimeout('hideGear()', 1000);
});
$('#Gear').mouseover(function() {
    clearTimeout(timeout);
});
$('#Gear').mouseout(function() {
    timeout = setTimeout('hideGear()', 1000);
});

});
//Calling all the functions to hide everything
function hideMens() {
    $('#Mens').hide();
}
function hideWomens() {
    $('#Womens').hide();
}
function hideKids() {
    $('#Kids').hide();
}
function hideGear() {
    $('#Gear').hide();
}

Any idea how to make the jquery a little but smaller?

  • 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-12T10:28:18+00:00Added an answer on May 12, 2026 at 10:28 am

    This is what I came up with
    for javascript:

    <script type="text/javascript">
    // JavaScript Document  
    $(document).ready(function() {
    var timeout;
    $("ul.navigation li").mouseover(function(){
            var $showDiv = $(this).attr("class").substr(4);
             $("#categories > div").each(function(){
                   if($(this).attr("id")==$showDiv){
                   $(this).show();
                }
                else
                {
                $(this).hide();
                }
    
       });
    });
    $("ul.navigation li").mouseout(function(){
    var $showDiv = "#" +  $(this).attr("class").substr(4);
      $("#categories > div").each(function(){
                   if($(this).attr("id")==$showDiv){
                   $(this).hide();
                }
    
           });
    });
    
    $("#categories > div").mouseover(function(){
     clearTimeout(timeout);
    });
    
    $("#categories > div").mouseout(function(){
    $currentDiv = $(this).attr("id");
    switch($currentDiv){
     case "Mens": timeout = setTimeout('hideMens()', 1000); break;
     case "Gear": timeout = setTimeout('hideGear()', 1000); break;
     case "Kids" : timeout = setTimeout('hideMens()', 1000);break;
     case "Womens" : timeout = setTimeout('hideWomens()', 1000);break;
    }
    });
    
    });
    
    //Calling all the functions to hide everything
    function hideMens() {
        $('#Mens').hide();
    }
    function hideWomens() {
        $('#Womens').hide();
    }
    function hideKids() {
        $('#Kids').hide();
    }
    function hideGear() {
        $('#Gear').hide();
    }
    
    </script>
    

    for html I wrapped the divs in another div with id “categories”

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

Sidebar

Related Questions

Imagine that I have this HTML snippet: <div></div> <br /> <div></div> <br /> <img
Let's imagine that I have something like this: <html> ... <div> <iframe src=test.html hash=r4d5f7></iframe>
I have a view_mine_and_others.php file that outputs this html <div class=rec id=1> <div class=val>343</div>
Imagine you have this: <div class=parent_with_height200px> <div class=left>This is the left floated text, size
imagine what we have something like this: <div id=xxx><p>Hello World</p></div> if we call .html
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
Let's imagine I have a bash script, where I call this: bash -c some_command

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.