Skip to main content
add fiddle
Source Link

I ended using this code, once the dropdown is closed no more events run.

$('.header-top-bar .toggle').on('click', function (event) {
  event.preventDefault();

  var $this = $(this),
      $content = $this.next('.toggle-content');

  if (!$content.hasClass('isOpen')) {
    $content.addClass('isOpen');

    setTimeout(function () {
      $document.on('click.headerToggle', function (event) {
        if (!$(event.target).closest($content).length) {
          $content.removeClass('isOpen');
          $document.off('click.headerToggle');
        }
      });
    }, 10);
  }
});

Thank you all for your help.

Fiddle

I ended using this code, once the dropdown is closed no more events run.

$('.header-top-bar .toggle').on('click', function (event) {
  event.preventDefault();

  var $this = $(this),
      $content = $this.next('.toggle-content');

  if (!$content.hasClass('isOpen')) {
    $content.addClass('isOpen');

    setTimeout(function () {
      $document.on('click.headerToggle', function (event) {
        if (!$(event.target).closest($content).length) {
          $content.removeClass('isOpen');
          $document.off('click.headerToggle');
        }
      });
    }, 10);
  }
});

Thank you all for your help.

I ended using this code, once the dropdown is closed no more events run.

$('.header-top-bar .toggle').on('click', function (event) {
  event.preventDefault();

  var $this = $(this),
      $content = $this.next('.toggle-content');

  if (!$content.hasClass('isOpen')) {
    $content.addClass('isOpen');

    setTimeout(function () {
      $document.on('click.headerToggle', function (event) {
        if (!$(event.target).closest($content).length) {
          $content.removeClass('isOpen');
          $document.off('click.headerToggle');
        }
      });
    }, 10);
  }
});

Thank you all for your help.

Fiddle

Source Link

I ended using this code, once the dropdown is closed no more events run.

$('.header-top-bar .toggle').on('click', function (event) {
  event.preventDefault();

  var $this = $(this),
      $content = $this.next('.toggle-content');

  if (!$content.hasClass('isOpen')) {
    $content.addClass('isOpen');

    setTimeout(function () {
      $document.on('click.headerToggle', function (event) {
        if (!$(event.target).closest($content).length) {
          $content.removeClass('isOpen');
          $document.off('click.headerToggle');
        }
      });
    }, 10);
  }
});

Thank you all for your help.