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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:16:12+00:00 2026-06-08T01:16:12+00:00

I am creating muti-level menu using jquery. When I click on a button in

  • 0

I am creating muti-level menu using jquery. When I click on a button in a given level I change the buttons colour and I display the next lower menu level for the button clicked.

For example, clicking “Polices” may show “New policy”, “Renew policy”, “Endorse policy” etc.

The “Policies” button is at level 1 and the others are at level 2. If I click another level 1 button I turn off (remove) the button colour class for all buttons except the button being clicked. For this button I toggle the button colour class (in case it’s being clicked off or clicked a second time).

1) The problem comes when I click a level two button in that ALL the level one buttons’ colour class are removed. So now I want to put type=”level01″ and type=”level02″ for the buttons in the different levels. (I call them buttons but they are actually anchor tags.)

This is my code to remove all but the current buttons’ colour class:

// remove the menuA-open class from all class menuA objects except the one being toggled
$(".menuA[name!=" + $(this).text() +"]").removeClass("menuA-open");

Note that the text on the button (the anchor tag’s innerHTML) is also in the name=”” parameter.

Now I want to say something like:

($(".menuA[name!=" + $(this).text() +"]") and $("menu[type]==$(this)[type])).removeClass("menuA-open");

but I’m failing find how to ‘and’ these two conditions correctly in jquery.

2) I use the text() function on $(this) in

$(".menuA[name!=" + $(this).text() +"]").removeClass("menuA-open");

because the anchor tag’s innerHTML has a small graphic appended to the text. So this works fine for text lengths less than 19 characters but from there on the test fails??

Can anyone please help?

Chris

  • 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-08T01:16:14+00:00Added an answer on June 8, 2026 at 1:16 am

    Further Update: Working demo http://jsfiddle.net/Jb2jP/1/

    $(document).ready(function() {
        $(".menuA").click(function(evnt) {
    
            evnt.preventDefault();
    
            $(".menuA").not(this).removeClass("menuA-open");
    
            // hide all other fieldset objects except the one being toggled
            $('fieldset').not($(this).next('fieldset')).hide();
    
            // toggle the fieldset following this link open or closed
            $(this).next('fieldset').toggle();
    
            // toggle the currently selected menuA-open class on or off
            $(this).toggleClass("menuA-open");
        });
    
        $("fieldset").mouseup(function() {
            return false;
        });
        $(document).mouseup(function(evnt) {
            // if user clicked anywhere outside our menus
            if ($(evnt.target).parent("a.menuA").length == 0) {
                // remove the menuA-open class from all class menuA objects
                $(".menuA").removeClass("menuA-open");
                // hide all fieldset objects
                $("fieldset").hide();
            }
        });
    });​
    


    Update: To chain multiple attribute-(not)-equals selectors together, simply concatenate them (see jQuery docs).

    $(".menuA[name='abc'][type='123']").removeClass("menuA-open");
    

    Specifically in your case though, this still probably won’t be necessary:

    var type = $(this).attr('type');
    $(".menuA").not(this).filter("[type='"type"']").removeClass("menuA-open");
    

    You can use the jquery .not() filter method to remove the current element from the matched set once you’ve done the selection:

    $(".menuA").not(this).removeClass("menuA-open");
    

    That is the way to do it.


    As an example of how you would get your attempt working (not recommending this at all though):

    $(".menuA[name!='" + $(this).text() +"']").removeClass("menuA-open");
    

    You need to wrap the results of $(this).text() in literal quotes within your string, since it contains a space. That should be the only syntactic problem, though again the .not() filter is the safest and most intuitive way to go about this.

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

Sidebar

Related Questions

Creating a site in with FrogCMS and using alot of jquery to create an
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating a simple RPG game, first time using XNA. Trying to get my character
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
Creating a table without tbody using javascript createElement/appendChild will not add tbody in Firebug
Creating sprite sheets aka texture atlases rather than using many hundres of individual images
creating a filter for a select menu and having a few problems! the first
Creating the closure is easy but using it is confusing for me. Here is
Creating MVC3 Razor Helper like Helper.BeginForm() says that it can be done using extension

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.