The usual approach is to bind the click handler directly to <body> , and then close it or hide your <div> . For instance:
render: function() { $('body').on('click', this.remove); this.$el.html('<div id="d"></div>'); return this; }, remove: function() { $('body').off('click', this.remove);
If you just want to hide the <div> rather than remove it, just attach the clicks on the <body> to a different method than remove ; you still want to remove the click handler from <body> to remove . In addition, you will want to block click events on your el view so that they do not fall into <body> .
Demo: http://jsfiddle.net/ambiguous/R698h/
If you have other elements that take care of click events, you can completely position the <div> to hide the <body> , and then bind the click handler to this. You can watch the jQuery BlockUI plugin to see how this is done.
source share