javascript - Why bootstrap dropdown calling window.onfocus -


when click on bootstrap dropdown link, custom set window.onfocus gets called.

why bootstrap calling window.onfocus method?

<ul class="nav navbar-nav navbar-right">   <li data-ng-show="username" class="">     <a href="javascript://" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">name<span class="caret"></span></a>     <ul class="dropdown-menu" role="menu">       <li><a href="#">logout</a></li>     </ul>   </li> </ul> 
window.onfocus = function() {   alert("window onfocus called"); } 

jsfiddle link

when click on menu, alert message shown.

because bootstrap triggers focus event on dropdown anchor clicked. event naturally bubbles dom tree until reaches window, , functionality invoked.

you can prevent this, using event.stoppropagation():

jquery(function($){     $('.dropdown-toggle').focus(function(e){         e.stoppropagation();     }); }); 

jsfiddle


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -