I have created a very simple jQuery "dropdown list" that consists of two div elements. When the first div is clicked, the second div is displayed. Now I want the second div to be closed again, when I click outside that div. But I can't (and actually don't want to, if it's not necessary) use a document- or body-event-listener like this:
$('#div2').click(function(e) {
doSomething();
e.stopPropagation();
});
$(document).click(function() {
$("#div2").hide();
});
Reason: I have other elements on the page that use e.stopPropagation();
and if a user clicked on those elements after opening the dropdown, it wouldn't close again.
I found this plugin, jALDropdown, that somehow handled to close the dropdown even if I click on e.stopPropagation();
, or even somewhere outside the page or the browser, and it doesn't seem to use any document/body-event-listener: http://india.assigninfo.com/assignlabs/jaldropdown
Sorrily it's not working with Opera, so I can't use it. And I didn't find a version of the sourcecode that was not minimized, thus I was not able to find out how it works.
Do you have any ideas how to archieve this behaviour, so that the dropdown closes (element is hidden) if I click outside the element, page or even browser, without a document/body-event-listener? Thanks!