Let's say I have a custom dropdown (). When the button is clicked, I want to open the menu, and when the user clicks outside the menu, I want it to close. So I am doing something like this:
$(myDropDown).mousedown(dropDownMouseDown); $("html").mousedown(htmlMouseDown,myDropDown); function dropDownMouseDown(event) { event.target.open(); event.stopPropagation();
Well, that works. But what if I add two of them? If I click to open the first, then the same on the second, then both will be open, because dropDownMouseDown stops the distribution, so htmlMouseDown will never be called for the first. How do I get around this? If I had only these two, then adding some logic for this would, of course, be easy, but if the quantity is dynamic? Also, maybe I do not want to call event.stopPropagation (), because it will do strange things in other libraries that I use that also listen to this event? I also tried putting this line: $ ("HTML"). MouseDown (htmlMouseDown, myDropDown) inside the dropDownMouseDown handler, but it will be called immediately anyway as soon as the bubbles reach the html element.
source share