I am trying to setup a fairly simple (imo) Javascript GUI, and am running into issues. I'm using jQuery. Here's what I want to do:
Have a bunch of squares next to some text, like this:
[ ] Text next to square
[ ] Text next to square 2
[ ] Text next to square 3
[ ] Text next to square 4
When you click one of the squares, an absolutely positioned floating div shows up. That floating div has some interface options.
At this point, if the user clicks anywhere OUTSIDE the floating div, the div should disappear. If the user clicks another box, the original div should disappear, and a new one should appear.
I am able to get the floating divs to show up correctly, but I'm having trouble hiding them. What I'm currently doing is attached a click handler to $(document)
in the function that show the floating div. Simplified code is below:
show(jqueryObj)
{
jqueryObj.show();
$(document).one("click", function () { jqueryObj.hide(); });
}
(Show is bound to a lick on one of the [ ]
boxes elsewhere)
The problem I run into is that the click event seems to bubble up, and function () { jqueryObj.hide(); }
is executed immediately. I've tried returning false
in show()
, but that didn't seem to resolve the issue. What should I be doing here?