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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:49:46+00:00 2026-05-23T19:49:46+00:00

I am developing a website and I can’t use jQuery (no discussion about this),

  • 0

I am developing a website and I can’t use jQuery (no discussion about this), so pure javascript and a custom javascript framework is used.

Actually I have found a situation that I don’t know how to handle:

I’ve a group of selectors, that for each one I add a “onclick” event to display / hide a div.

For example:

<div id="menu">
    <div class="menu-item">
        <div class="arrow">
            <a class="down">Open / Close</a>
        </div>

        Menu Item

        <div class="extramenu hidden">
            Extra menu items
        </div>
    </div>

    <div class="menu-item">
        <div class="arrow">
            <a class="up">Open / Close</a>
        </div>

        Menu Item 2

        <div class="extramenu">
            Extra menu items
        </div>
    </div>

    <div class="menu-item">
        <div class="arrow">
            <a class="down">Open / Close</a>
        </div>

        Menu Item 3

        <div class="extramenu hidden">
            Extra menu items
        </div>
    </div>
</div>

I select all “div.menu-item .arrow a” items, so I’ve 3 items. For each item I add a onclick event (that actually works fine).

What I need to archive is how to select the “closest” class .extramenu inside the div.menu-item. Then detect if the <a /> have a class .up or .down and if class == .up, add the class hidden; and if class == .down, remove the class hidden.

This a concept of what have to do, it’s not javascript code:

var elements; // my list of elements

each(elements, function(element) {
    // here element is pointing to the ANCHOR
    add_event(element, "onclick", function(e) {
        var submenu; // here I need to detect the submenu closest to my anchor
        var state; // here I need to know if the anchor has class up or down

        if (state == "up")
        {
            add_class(submenu, "hidden"); // hide the submenu div
            remove_class(element, "up"); // remove the class up
            add_class(element, "down"); // and add the class down
        }
        else if (state == "down")
        {
            remove_class(submenu, "hidden"); // remove the class to show the menu
            remove_class(element, "down"); // remove the class down
            add_class(element, "up"); // and add the class up
        }
    });
});

Thank you guys and sorry if it’s not well explained, I did my best!

  • 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-23T19:49:48+00:00Added an answer on May 23, 2026 at 7:49 pm

    element.querySelectorAll allows you to select elements by CSS selector.

    element.classList allows you to access the classes of an element

    add_event(element, "onclick", function(e) {
        var el = e.target, state;
        var parent = el.parentNode;
        while (!parent.classList.contains('menu-item')) {
            parent = parent.parentNode;
        }
        var submenu = parent.querySelector('extramenu');
            if (el.classList.contains('up')) {
            state = 'up';
        } else {
            state = 'down'
        }
    
        /* ... */
    });
    

    You can write the rest of the pseudo code yourself.

    I’m assuming your already using Modernizr for supporting legacy browsers like IE8. If your not, then do so.

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

Sidebar

Related Questions

Since, for various reasons, I can't use IIS for an ASP.NET website I'm developing,
I am developing a website similar to this site in PHP and jQuery. As
can we use JQ insted of php for developing website. which one is more
What is mvc ? What are the benefits developing mcv website ? How can
i am developing android application website address how can implemented validation example : www.yahoo.com
I'm developing a website using php, i want to know how can i protect
I'm developing a website in Drupal 6. I've 3 blocks (I use as footers),
I'm currently developing a website, you can find it [here] ! It's work in
I am developing a website using ASP.Net MVC 1.0. Can i host that website
I'm developing a website that incorporates an XMPP bot and a custom SMTP server

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.