-1

I have some DIV that fades in by clicking another DIV trigger element. I cannot came up with a script that will:

  • On mouse leave then click outside -fade out the DIV

Thanks for any advice.

Wolly Wombat
  • 99
  • 1
  • 1
  • 9

1 Answers1

1

If i understood you correctly, this is what you want:

$(document).ready(function(){

  var button = $("#div1");
  var container = $("#div2");    

  button.on('click', function(){

       container.fadeIn();

  });      

  $(document).mouseup(function (e){

        // check if click target is element or one of its children
        if (!container.is(e.target) && container.find(e.target).length == 0){

            container.fadeOut();

        }
  });

});

Here's the fiddle: http://jsfiddle.net/neQuK/

Cristi Pufu
  • 9,002
  • 3
  • 37
  • 43