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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:14:23+00:00 2026-05-21T15:14:23+00:00

hey guys, I’ve build my own kind of select box in html with css

  • 0

hey guys,
I’ve build my own kind of select box in html with css and jquery.

<div class="select">
    <ul>
        <li class="destination option small darr loc">One</li>
        <li class="destination option small loc">Two</li>
        <li class="destination option small loc">Three</li>
        <li class="destination option small loc">Four</li>
    </ul>
</div>

jQuery:

   //select box
$('.select ul li.option').click(function(e) {
    e.stopPropagation();
    $(this).siblings().slideToggle(100).removeClass('darr');
    $(this).addClass('darr');
});

$(document).click(function(e) {

    $('.select ul li.option').each(function() {

        if ( !$(this).is(":hidden") ) {
            $(this).not('.darr').slideToggle(100);
        }

    });

});

So when clicking on the first Item the selectbox expands like a dropdown. When clicking one of the options the select box collapses again.

I also want the selectbox to collapse when clicking somewhere else on the page, therefore I’m listening to click events on the $(document). That works just fine.

Only little bug I have is, when having multiple of those selectboxes on the page and I expand onr of them and click on another selectbox the previous one doesn’t collapse.

See my example here: http://jsfiddle.net/UWSUk/
When you expand the second select box and then directly click on the one above it doesn’t collapse. Both stay open.

Any idea how to fix that?

  • 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-21T15:14:24+00:00Added an answer on May 21, 2026 at 3:14 pm

    You can fix this by:

    1. Allowing propegation
    2. Assigning IDs to the parent divs of each ul
    3. Storing off the div of each clicked li
    4. Only collapsing lis that don’t have the stored parent ID.

    The id attribute comparison check should work because IDs must be unique in the page.

    You can see it working here.

    Here’s the Javascript:

    var currentSelectDiv = null;
    $('.select ul li.option').click(function(e) {
        // store the id attribute
        currentSelectDiv = $(this).parents("div.select").attr("id");
    
        $(this).siblings().slideToggle(100).removeClass('darr');
        $(this).addClass('darr');
        // allow bubbling because we want this event to close other classes
    });
    
    $(document).click(function(e) {
        $('.select ul li.option').each(function() {
            // check IDs to make sure we are only closing the other lis, not our own
            if($(this).parents("div.select").attr("id") !=
               currentSelectDiv) {
                if ( !$(this).is(":hidden") ) {
                    $(this).not('.darr').slideToggle(100);
                }
            }
        });
        // clear the currently clicked parent
        currentSelectDiv = null;
    });
    

    And here is the HTML:

    <div class="select" id="first" style="z-index:2">
        <ul>
            <li class="destination option small darr loc">One</li>
            <li class="destination option small loc">Two</li>
            <li class="destination option small loc">Three</li>
            <li class="destination option small loc">Four</li>
        </ul>
    </div>
    
    <div class="select" id="second">
        <ul>
            <li class="destination option small darr dest">Five</li>
            <li class="destination option small dest">Six</li>
            <li class="destination option small dest">Seven</li>
            <li class="destination option small dest">Eight</li>
        </ul>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
Hey guys I'm just learning javascript, I have some html and css background though.
Hey guys am having a bit of problems with my jQuery, I have all
Hey guys I'm making a chat program and I have a parent MessagePacket class
Hey guys so in JQuery ui it produces a close link that once clicked
Hey guys bit of an odd questions but if I add div tags using
Hey guys today I started to develop my own little alarmclock app. But now
Hey guys plz help I am trying to convert this html to jade using
hey guys I have a problem adding text inside an added html-tag I have
Hey guys i'm kind of new to the whole world of mysql, the current

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.