0

I created a simple dropdown for my framework ..., I want to close it when other areas except dropdown clicked like Bootstrap.

This is my code :

$('.ji-dropdown-click button').click(function () {
    var animationObject = $(this).parent().find('.ji-dropdown-menu').data('animation');
    $(this).parent().find('.ji-dropdown-menu').toggle().addClass('animated' + ' ' + animationObject);
});

Can you please help me ? Thanks ...

  • 1
    try this you have to identify if the user click from the outside of your element http://stackoverflow.com/questions/152975/how-to-detect-a-click-outside-an-element – caldera.sac Aug 19 '16 at 08:28
  • http://stackoverflow.com/questions/38561315/hide-the-drop-down-menu-when-clicking-outside/38561407#38561407 refer to this – Shubham Khatri Aug 19 '16 at 08:31
  • Thanks both, But @AnuradhS It was exactly that I wanted ... Thanks Again ... –  Aug 19 '16 at 08:56

2 Answers2

0

You can use this code:

$('body *:not(.ji-dropdown-click)').click(function() {
   $('ji-dropdown-click').hide(500);
});
Folusho Oladipo
  • 362
  • 3
  • 11
  • Thanks, But It doesn't work ..., I put that in my inside my code & outside my code but It always hide it ... –  Aug 19 '16 at 08:54
0

Try this code:

$(document).click( function(){
    $('.ji-dropdown-menu').hide();
});

It should work.

grec0o
  • 100
  • 1
  • 6
  • On a side note, jquery's animate functions have poor performance. I would suggest using [Velocity.js](https://github.com/julianshapiro/velocity) – Kostas Pelelis Aug 19 '16 at 12:10