-2

I need was when a popup comes and user clicks any where in the document except the popup, the popup should fadeout.

I have tried out with target.attr method, but failed in Mozilla.

IS there any Idea ? Thanks in Advance

Surjith S M
  • 6,642
  • 2
  • 31
  • 50

4 Answers4

2

You can use the jQuery fadeout method and one method.

Something like :

jQuery("#yourpoup").click(function(){ return false; });
jQuery(document).one("click", function() { jQuery("#yourpoup").fadeOut(); });

According to this question, using this is better then using bind.

Community
  • 1
  • 1
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
0

There is also a JQuery plugin for click outside, this will allow you to handle the click even for everything BUT the pop up.

http://benalman.com/projects/jquery-outside-events-plugin/

$("#yourpopup").bind( "clickoutside", function(event){
$(this).fadeOut(500);
});
box86rowh
  • 3,415
  • 2
  • 26
  • 37
0

If your pop-up is a JQuery Dialog, you can see this thread:

jQuery UI - Close Dialog When Clicked Outside

Community
  • 1
  • 1
Melanie
  • 1,198
  • 2
  • 17
  • 42
0

Use jquery as example, assumed $popup is the your popup element

$('body').click(function(){
    // hide the popup here
});

$popup.click(function(e) {
    // do something here if needed
    e.stopPropagation();
});

The key is when click in the popup, stop bubble the event to body, so will not fire the function attached to body.

liunian
  • 440
  • 2
  • 6