Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle with click effect [duplicate]

Possible Duplicate:
How to detect a click outside an element?

 <ul id="rightNav">

      <li id="SettingOpt">
        <a href="javascript:void(0)">username<span class="fabShopSprite iRecentIcon iUserIcon"></span></a>
        <div class="userMenu">
          <ul>
            <li><a class="Setting" href="/">Settings</a></li>
            <li><a class="Setting lastShadow" href="/">Logout</a></li>
          </ul>
        </div>
      </li>

    </ul>

It is working proper as a menu, but my requirement is when a user click out side this block it goes of and another effect i want toggle effect, toggle effect is working fine for me, but when i click out side of that wrap #rightNavToggle its not going off. My another requirement is when a user click on its sub navigation, again the sub navigation should goes off. Used Java script

$("#SettingOpt a").click(function() {
        var parent = $(this).parent();
        parent.toggleClass("selected");
        parent.find("div.userMenu").toggle();
      });
like image 856
Soarabh Avatar asked Apr 10 '11 13:04

Soarabh


1 Answers

Just made a simple example based upon @syrion ref. http://jsfiddle.net/cfmitrah/5grcu/

like image 183
JS Mitrah Avatar answered Oct 11 '22 09:10

JS Mitrah