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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:02:34+00:00 2026-05-13T20:02:34+00:00

i have a page around 500 div as below. <div onclick=’test()’ class=’test> <ul class=’innermenu’>

  • 0

i have a page around 500 div as below.

<div onclick='test()' class='test>
     <ul class='innermenu'>
       <li>1</li>
       .....
      </ul>
  </div>

when the test function is called it need to hide the menu (innermenu) who calls that function.

my problems are

  1. uniquely identify the div without using id

  2. How to hide only the particular ul alone.

  • 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-13T20:02:35+00:00Added an answer on May 13, 2026 at 8:02 pm

    OK, first the quick fix, though it is not the best way to use JS on your page:

    Change the call to this:

    <div onclick="test(this);" class="test">
    

    Then, in test, use this:

    function test(el){
       var uls = el.getElementsByTagName('ul');
       for(var i = 0; i < uls.length; i++){
          if(uls[i].className == 'innermenu'){
             uls[i].style.display = "none";
             break;
          }
       }
    }
    

    This will hide just the child ul of the div that is clicked.

    A better way

    OK, for the longer answer. Either attach the events after the fact using attachEvent and addEventListener or use a library like jQuery to help you out. Here is the raw solution:

    Set up your HTML this way (no onclick):

    <div class="test">
    

    And then at the very end of your HTML put this:

    <script type="text/javascript">
        var divs = document.getElementsByTagName('div');
        function test(){
          var uls = this.getElementsByTagName('ul');
          for(var i = 0; i < uls.length; i++){
             if(uls[i].className == 'innermenu'){
                uls[i].style.display = "none";
                break;
             }
          }
        };
    
        for(var i = 0; i < divs.length; i++){
          var div = divs[i];
          if(div.className !== "test") continue;
          if(window.addEventListener){
             div.addEventListener( 'click', test, true ); //FF, Webkit, etc
          } else if (window.attachEvent) {
             div.attachEvent('onclick', test); // IE
          } else {
             div.onclick = test; // Fallback
          }
        }
    </script>
    

    Now, you don’t have JavaScript code in your HTML, and you can get rid of the extra parameter on the test function.

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

Sidebar

Related Questions

I have around 9 web parts and 3 pages to be deployed. Each page
I need something simple; I have page where a user clicks an author to
I have a page where there is a column and a content div, somewhat
I have a page that shows a bunch of thumbnails (around 30), and the
I have a section of a web page that I need to take a
I have a page here that has a div with an Facebook recommend button.
I have a page that uses a bit of jQuery and an effect called
I need it so when I click on a div of class 'mydiv', all
Let say I have a page with 100 objects and each page is around
I have a page with some HTML on which I need to get hold

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.