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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:26:48+00:00 2026-06-06T23:26:48+00:00

I have the following html to create a dropdown menu: <li class=user-section user-section-original> <img

  • 0

I have the following html to create a dropdown menu:

<li class="user-section user-section-original">
    <img class="user-image" src="{{ user.get_profile.avatar_small.url }}" height="30" width="30"/>
    <span class="name">{{ user.first_name }} {{ user.last_name.0}}.</span>
</li>
<li class="user-section-dropdown user-section hidden">
    <img class="user-image" src="{{ user.get_profile.avatar_small.url }}" height="30" width="30"/>
    <span class="name">{{ user.first_name }} {{ user.last_name.0}}.</span>
    <a href="{% url logout %}" class="dropdown-item">Log Out</a>
</li>

When a user clicks the menu, it will dropdown, and then if the user clicks it again (or clicks anywhere outside of the dropdown menu), it will hide again.

Here is what I have so far:

$("#header li.user-section").click(function() {
    $("#header .user-section-dropdown").css('display', 'block');
    $("#header .user-section-original").css('display', 'none');
});

This makes the account dropdown appear when the account section is clicked. How would I make it also disappear when it is clicked again or another section on the page is clicked?

  • 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-06T23:26:49+00:00Added an answer on June 6, 2026 at 11:26 pm

    You simply need to add click listener to whole document and hide the dropdown if it is shown.

    $(document).click(function() {
        if($("#header .user-section-dropdown").css('display') == 'block') {
            $("#header .user-section-dropdown").css('display', 'none');
            $("#header .user-section-original").css('display', 'block');
        }
    });
    

    Also, you need to modify the original function so that it handles both cases:

    $("#header li.user-section").click(function(e) {
        if($("#header .user-section-dropdown").css('display') == 'none') {
            $("#header .user-section-dropdown").css('display', 'block');
            $("#header .user-section-original").css('display', 'none');
            e.stopPropagation()
        }
        else {
            $("#header .user-section-dropdown").css('display', 'none');
            $("#header .user-section-original").css('display', 'block');
        }
    });
    

    e.stopPropagation() is used to not let the document click handler get called.

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

Sidebar

Related Questions

I have following HTML <tr id=r1 class=l1> <td><img class=plusminus id=r1c1 src=assets/images/plus.png border=0 />3/10/12</td> <td></td>
I have following HTML <div id=header1 class=toggle>Section 1 : Create an account</div> <div id=section1>
I have created a jquery dropdown menu with the following HTML: <dl class=dropdown> <dt><a
I have the following HTML: <DIV class=foo bar></DIV> I'm trying to create a CSS
I have the following HTML code: <div id=event_create> <img src=WEB-INF/images/Classifieds/create_blurred_135x135.png name=createbutton onmouseover=buttondown('createbutton') onmouseout=buttonup('createbutton') onclick=buttonclick('createbutton')
I have the following html: <div id='social'> <img src=twitter.png alt=Twitter/> </div> <h1>Heading</h1> I would
In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
I am following the guide at http://guides.rubyonrails.org/association_basics.html and I have created class Customer <
I have following HTML: <div class=olympics style=display: block; position: absolute; left: 250px; top: px;>
I have the following html table <table id={64ED3A94-5833-4CC7-869F-CCE583B498BE} class=ms-listviewtable width=100% cellspacing=0 cellpadding=1 border=0 xmlns:o=urn:schemas-microsoft-com:office:office

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.