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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:11:15+00:00 2026-05-22T15:11:15+00:00

I want to turn the JavaScript in this example into jQuery. Basically I’ve jerry-rigged

  • 0

I want to turn the JavaScript in this example into jQuery.

Basically I’ve jerry-rigged two scripts together. One is jQuery; creates the “active” function. But the hide/display layer function is in Javascript, and there’s too much code for my liking, I’m thinking it must be possible to cut it down into something simple and effective with jQuery.

FYI, I just started out with Javascript and jQuery.

Help?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JSMenu</title>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript" language="JavaScript">
function HideLayer(d) { document.getElementById(d).style.display = "none"; }
function DisplayLayer(d) { document.getElementById(d).style.display = "block"; };

 $(function() {
    $('div.menuitem').click(function() {
        var $this = $(this);
        $('.active').removeClass('active');
        $this.addClass('active');
    })
});
</script>

<style>
#menuholder {width:100px; float:left; border-bottom:solid thin #000;}
.menuitem {border-top:solid thin #000; border-left:solid thin #000; border-right:solid thin #000;}
.menuitem:hover {cursor:pointer; color:#555}
.active {font-weight:bold; color:#000}
.active:hover {color:#000}
#layerholder {float:left; margin-left:20px; width:50px; height:50px; border:solid thin;}
.layer {padding-left:3px; font-size:36px; display:none;}
</style>

</head>

<body>

<div id="menuholder">
<div onClick="DisplayLayer('firstLayer');HideLayer('secondLayer');HideLayer('thirdLayer');HideLayer('fourthLayer')" class="menuitem">Item 1</div>
<div onClick="HideLayer('firstLayer');HideLayer('thirdLayer');HideLayer('fourthLayer');DisplayLayer('secondLayer')" class="menuitem">Item 2</div>
<div onClick="HideLayer('firstLayer');HideLayer('secondLayer');HideLayer('fourthLayer');DisplayLayer('thirdLayer')" class="menuitem">Item 3</div>
<div onClick="HideLayer('firstLayer');HideLayer('secondLayer');HideLayer('thirdLayer');DisplayLayer('fourthLayer')" class="menuitem">Item 4</div>
</div>

<div id="layerholder">  
<div class="layer" id="firstLayer">1</div>
<div class="layer" id="secondLayer">2</div>
<div class="layer" id="thirdLayer">3</div>
<div class="layer" id="fourthLayer">4</div>
</div>
<div style="clear:both;"></div>

</body>
</html>
  • 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-22T15:11:15+00:00Added an answer on May 22, 2026 at 3:11 pm

    You could change your HTML to:

    <div id="menuholder">
       <div rel="firstLayer" class="menuitem">Item 1</div>
       <div rel="secondLayer" class="menuitem">Item 2</div>
       ...
    </div>
    

    And then use this jQuery:

    $('.menuitem').click(function() {
        $('.layer').hide();
        $('.active').removeClass('active');
        $(this).addClass('active');
        $('#' + $(this).attr('rel')).show();
    });
    

    This also not 100% perfect as rel is not a valid attribute for div elements. You should consider changing the divs to a elements (and use the href attribute) which has the benefit that the browser also jumps to the linked element.

    DEMO

    Update: If you decide to go with links, it would be:

    <div id="menuholder">
       <a href="#firstLayer" class="menuitem">Item 1</div>
       <a href="#secondLayer" class="menuitem">Item 2</div>
       ...
    </div>
    

    and

    $('.menuitem').click(function() {
        $('.layer').hide();
        $('.active').removeClass('active');
        $(this).addClass('active');
        $(this.href).show();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to turn a program I have into a service so I can
I want to take html, including the text and images and turn it into
I'm getting more into jQuery and so have set up a HTML/Javascript/CSS base site
I want to turn off PHP's magic quotes. I don't have access to php.ini.
dev%40bionic%2Dcomms%2Eco%2Euk I want to turn the above back in to readable text. Can anyone
I have a control that I'm writing where I want to turn off .NET's
I want to setup a CRON that runs a PHP script that in turn
Using a configuration file I want to enable myself to turn on and off
I want to let the users of my app, which is in turn an
Say you in JavaScript are handed a single DOM element or Document (for example

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.