All welcome.

I wrote a simple script

$(function() { $("#uuser").click(function() { $("#uuser_b > ul").animate({ opacity: "toggle" }, 200); }); }); 

Just add or hide the block when clicking on #uuser. How to make it so that if I clicked on any space around #uuser_b> ul, then this block would hide?

    2 answers 2

     $(document).click(function(e) { if (!$(e.target).is("#uuser_b > ul, #uuser")) { $("#uuser_b > ul").animate({opacity: 0}); } }); $("#uuser").click(function() { $("#uuser_b > ul").animate({ opacity: 1 }, 200); }); 

    http://jsfiddle.net/FqhpK/18/

    • It’s probably better to check in the second line: if (! $ (E.target) .is ("# uuser_b, #user_b *, #uuser")) - Bars
    • @Bars no, not better. In your case there are 3 iterations. - lampa
    • when we are on one, two, three in your example, they disappear. And this is bad - inferusvv
    • @ inferus-vv, So there only a selector should be slightly corrected. We look here - Deonis
     $(function() { $("#uuser").click(function(e) { e.stopPropagation(); $("#uuser_b > ul").animate({ opacity: "toggle" }, 200); }); }); 

    did not check in work

    • Not working - inferusvv