javascript - Listening for a click anywhere on the page without jQuery -


i have dropdown menu toggles on click, , i've gotten rid of jquery can toggle menu using angularjs. problem if dropdown section visible, have click button again hide it. way toggle menu use button right now, , want users able close menu clicking somewhere on page isn't menu.

so here's code right now:

<button type="button" class="btn btn-nav dropdown-toggle" aria-expanded="false" ng-click="showmenu = !showmenu">     {{ getnavtitle() | translate }} <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu" ng-class="{ show: showmenu === true }">     <li>         <a id="hottest" ng-click="nav.replaceto('/one')" ng-class="{active: subnav === 'top'}"><big>{{ 'subnav-one' | translate }}</big></a>     </li>     <li>         <a id="latest" ng-click="nav.replaceto('/two')" ng-class="{active: subnav === 'latest'}"><big>{{ 'subnav-two' | translate }}</big></a>     </li>     <li>         <a id="friends" ng-click="nav.replaceto('/three')" ng-class="{active: subnav === 'fans'}"><big>{{ 'subnav-three' | translate }}</big></a>     </li> </ul> 

angularjs:

$scope.showmenu = false; 

so works. jquery listen tap somewhere on page wasn't 1 of 3 drop down links , toggle button, , close menu. angularjs, i'm unsure how go doing that.

i guess you're using bootstrap. use angular-bootstrap or bootstrap.js itself. think auto close feature should implemented there.

if wanna implement add click event handler, closes menu, body 'once', handler executed once , removed event listeners.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -