Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! I use bootstrap's Button dropdown menus and there is code:

XML
<div class="btn-group open">
  <button class="btn btn-mini" data-toggle="dropdown">AN</button>
  <button class="btn btn-mini dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu">
    <li><input type="checkbox" name="currency[]" value="1" id="1"> <span>AZN</span></li><li><input type="checkbox" name="currency[]" value="3" id="3"> <span>EUR</span></li><li><input type="checkbox" name="currency[]" value="4" id="4"> <span>RUB</span></li>
  </ul>
</div>



C#
$(document).ready(function(){

$('.dropdown-menu').blur(function() {
  alert('s');
  $(this).hide();
});


I try to close block after it lose focus.
Why my block .dropdown-menu does not hide?
Posted
Comments
Sergey Alexandrovich Kryukov 10-May-13 16:02pm    
First of all, you have unbalanced {} brackets in your script
—SA
Jardin1 10-May-13 16:13pm    
Made here:

$('.dropdown-menu').mouseleave(function(event) {
$(this).closest('div.btn-group').removeClass('open');
});

Does not work
Jardin1 10-May-13 16:19pm    
Thank you!

1 solution

onblur event is not standard on div elements, it is meant for input tags. Use onmouseleave instead. onmouseout won't work correctly either - see the explanation: http://www.mkyong.com/jquery/different-between-mouseout-and-mouseleave-in-jquery/[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-May-13 16:06pm    
My 5. I would say, this is because the element "ul" (this is ul, not div) is not a selectable element, you can do such things on controls only. Besides, the brackets in code are not balanced.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900