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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:49:46+00:00 2026-06-03T22:49:46+00:00

Edit: Looking for a way to close the dropdown when anything but the button

  • 0

Edit: Looking for a way to close the dropdown when anything but the button is clicked: http://jsfiddle.net/brennan/s4JTn/

I’m looking to (re)create twitter’s dropdown menu in my ember app. I’m specifically having an issue trying to close the dropdown when anything except the dropdown is clicked. Ie. I’m looking for a way to add an event listener to my app to close my dropdown when the body of the app is clicked.

Here’s my (child) view.

categorySelect: Ember.View.extend({
    isOpen: false,
    selected: /* removed for brevity */,
    content:[
        /* removed for brevity */
        /* follows structure: {slug: 1, title: 'title', isActive: true} */
    ],

    dropdownToggle: function(e){
        var open = this.get('isOpen');
        if(open){
            this.set('isOpen', false);
        }else{
            this.set('isOpen', true);
        }
    },
    select: function(e){
        var selected = e.context;

        this.content.setEach('isActive', false);

        this.set('selected', selected);
        selected.set('isActive', true);

        this.set('isOpen', false);
    }
})

and here is my template code…

{{#view categorySelect tagName="div" class="btn-group" classBinding="isOpen:open"}}
                        <a class="btn dropdown-toggle btn-facebook btn-small" {{action "dropdownToggle" on="click"}} href="#">
                            {{selected.title}}
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            {{#each content}}
                            <li {{bindAttr class="isActive:active"}}><a href="#" {{action "select" on="click"}}>{{title}}</a></li>
                            {{/each}}
                        </ul>
                    {{/view}}

I’ve tried adding event listeners to the body like the following which isn’t working. Ember seems to stop propagation if I click on any ember views. So while it works if I click directly on the body, it doesn’t work if i click on any of my views 🙁

didInsertElement: function(){
        var self = this;
        $('body').on('click', function(){
            self.set('isOpen', false);
        });
    },

Looking for help and advice. Also, if any of the above code looks like crap please let me know I’m looking to learn as much as I can.

  • 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-03T22:49:47+00:00Added an answer on June 3, 2026 at 10:49 pm

    I have roughly the same setup as you that works by creating an event listener on the body element using didInsertElement as well.

    Only difference is I have a e.stopPropagation() call in dropdownToggle:

    dropdownToggle: function(e){
        // [removed]
        e.stopPropagation();
    },
    

    Without that line, I was unable to keep the dropdown open, as the click on the dropdown propagates to the body and immediately closes it.

    On my setup, clicks on views do propagate to the body (hence the above code), and clicking on other views does trigger the event listener on the body.

    My guess is you have some code in your other views stopping the propagation to the body?

    Try http://jsfiddle.net/bjaeP/ for an example.

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

Sidebar

Related Questions

[Edit (Haren): Duplicate ] I'm looking for a way to automatically wrap my NUnit
I was looking for a way to call the edit method directly. - (void)tableView:(UITableView
[edit] I am NOT using jquery in this app. Looking for a way to
Is there a best way to edit CSS? I'm looking for a designer tool.
I'm looking for close event for popup. I've found one for XUL , but
I'm looking for a way to create a simple HTML table that can be
EDIT I'm looking for the actual one or two liner that does what the
edit: I'm not looking for you to debug this code. If you are familiar
Edit: just to be clearer on what I am looking to do. I have
We're looking at moving from a check-out/edit/check-in style of version control system to Subversion,

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.