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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:21:29+00:00 2026-06-13T06:21:29+00:00

I have a View in Backbone that contains an inner div. I want to

  • 0

I have a View in Backbone that contains an inner div. I want to hide the div when the user clicks outside of the div.

I’m not sure how to set up an Event inside of the View that says “click NOT #inner_div”: “removeDiv”.

Any suggestions on how to do this?

  • 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-13T06:21:30+00:00Added an answer on June 13, 2026 at 6:21 am

    The usual approach is to attach a click handler directly to <body> and then have that close or hide your <div>. For example:

    render: function() {
        $('body').on('click', this.remove);
        this.$el.html('<div id="d"></div>');
        return this;
    },
    remove: function() {
        $('body').off('click', this.remove);
        // This is what the default `remove` does.
        this.$el.remove();
        return this;
    }
    

    If you just want to hide the <div> rather than remove it, just bind clicks on <body> to a different method than remove; you’ll still want to remove the click handler from <body> in your remove though. Also, you’ll want to trap click events on your view’s el to keep them from getting to <body>.

    Demo: http://jsfiddle.net/ambiguous/R698h/

    If you have other elements that care about click events then you could absolutely position a <div> to cover up the <body> and then bind your click handler to that. You could have a look at the jQuery BlockUI plugin to see how this is done.

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

Sidebar

Related Questions

I have backbone view that binds an action to an element in the DOM.
I have a Backbone View that has a Collection as its Model. If the
I have a standard list view setup with backbone that looks something like below.
I have created a street view backbone view. The problem is that when shown,
I'm having an issue with backbone.js' models. I have a view that creates another
In my Backbone application I have a main view that shows previews of posts.
I have a backbone view that has render() called from its parent view returning
I have a backbone view that is initialized via route, but i when i
I have a view that includes a table. var newsIndexView = Backbone.View.extend({ ... });
I have a view that creates and populates a Selectlist. I want to bind

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.