Q:

jQuery functions not working after using $(document).click

All functions stop working after I use for the first time this function:
$(document).ready(function(){
  var popbox = '#popbox';

  $(document).click(function(event){
      if(!$(event.target).closest(popbox).length && !$(event.target).hasClass('popper')){
          if($(popbox).is(":visible")){
              $(popbox).hide();
          }
      }
  });

For example
  $('#ajax').on('click', 'span.popper', function(){
      $('#ajax').off('mouseenter mouseleave mousemove', 'span.popper');
  })
  .on('mouseenter', 'span.popper', popperMouseenter)
  .on('mouseleave', 'span.popper', popperMouseleave)
  .on('mousemove', 'span.popper', function(e){
      popperMousemove(e);   
  });
});

does not work anymore. But before clicking outside #popbox everything works fine. Why?
EDIT: ADDED INFORMATIONS
When mouse enter a span a div #popbox appears (.show()) calling ajax data.
This div holds if the user clicks on it.
I want #popbox to .hide() if the user clicks outside it: this is done by the $(document).click function.
But when reentering on #popbox nothing is showed nor ajax is called if the user clicked outside calling the $(document).click function. Otherwise everything works fine.

A:

I guess your problem is you are defining the popbox outside the function.
You can try this. It worked for me.
$(document).click(function(e) {
    var popbox = $('#popbox');

    if (!popbox.is(e.target) && popbox.has(e.target).length === 0) {
        if ($(popbox).is(":visible")) {
            popbox.hide();
        }
    }
});

jsFiddle

