Search code examples
jqueryasp.netdomdopostback

window.click event issue in JQuery


I have a common scenario in which when clicking the window dismisses a popup div. The code I use is

   $(window).load(function (){
   $('.popupstyle').live("click", function(e){
       return false;
    });
    });
   $(document).ready(function(){
   $(window).click(function(){
   $('.popupstyle').hide();
    });
  });

but the problem is that no postback event of controls Like LinkButton is working on popup div then. return false in click event of the popup div creates a problem.It fuses everything on popuop div. Don't understand what to do fixing one thing disturbs the other. also the live event does not work on first click. Any suggestions


Solution

  • The cause of this is event bubbling , where the event from the child element bubbles to the parent element..

    One way of preventing this is to use e.stopPropagation() when you encounter the target element

    CHECK FIDDLE