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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:45:33+00:00 2026-06-03T14:45:33+00:00

I wanted a lightweight solution so i found this one, however it only expands

  • 0

I wanted a lightweight solution so i found this one, however it only expands on clicking plus sign “+” next to the name of expandable category. I replaced + for red square and – for blue square for this demonstration to work.
Live code at: http://jsfiddle.net/2VXuk/2/

I need help modifying it to make any sub level that is expandable to be category that’s not a link and upon clicking on its name expand its content.

Would be great to have option to make it a category – expand on click or link expand on + click and redirect on name click.
e.g.

<ul id="sitemap">
<li><a class="category" href="#">expands only</a> 
    <ul>
        <li><a href="#">Sample</a></li>
        <li><a href="#">Sample</a></li>
        <li><a class="category_and_link" href="psy.html">Link to page or expand on + button</a>
            <ul>
                <li><a href="#">Sample</a></li>
                <li><a href="#">Sample</a></li>
                <li><a href="#">Sample</a></li>
                <li><a href="#">Sample</a></li>
                <li><a href="#">Sample</a></li>
            </ul>                           
        </li>
        <li><a href="#">Fourth link</a></li>
        <li><a href="#">Fifth link</a></li>
    </ul>                   
</li>
</ul>

<script type="text/javascript">
this.sitemapstyler = function(){
    var sitemap = document.getElementById("sitemap")
    if(sitemap){

        this.listItem = function(li){
            if(li.getElementsByTagName("ul").length > 0){
                var ul = li.getElementsByTagName("ul")[0];
                ul.style.display = "none";
                var span = document.createElement("span");
                span.className = "collapsed";
                span.onclick = function(){
                    ul.style.display = (ul.style.display == "none") ? "block" : "none";
                    this.className = (ul.style.display == "none") ? "collapsed" : "expanded";
                };
                li.appendChild(span);
            };
        };

        var items = sitemap.getElementsByTagName("li");
        for(var i=0;i<items.length;i++){
            listItem(items[i]);
        };

    };  
};

window.onload = sitemapstyler;
</script>
  • 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-03T14:45:34+00:00Added an answer on June 3, 2026 at 2:45 pm

    See my fork of your jsFiddle. The basic idea is to grab the a element…

    var a = li.getElementsByTagName("a")[0];
    

    and add an event handler to it as well.

    if (!a.hasAttribute("href"))
        a.onclick = showHide;
    

    For non-links, just leave out the href attribute.

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

Sidebar

Related Questions

Wanted to share a way I found to remove strong name from assembly name.
I wanted to show the users Name Address (see www.ipchicken.com ), but the only
Wanted to add an alias for one of the charsets that PayPal may use
Are there any lightweight frameworks out there for this task. I have a collection
I'm looking to setup a lightweight, developer only web stack on Windows (and possible
Wanted to create a fun app with photo. This is the scenario: I have
wanted a solution on how to access the javascript variable inside the java scope.
Wanted to know, because side effect of this could be to alert user that
I wanted to know if this is possible? I would like to create a
Wanted to know if I could do this without the sub-query SELECT * FROM

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.