user2412230
user2412230

Reputation: 63

Jquery capture click event outside of popup

Im using bPopUp to show a hidden div that is working well. This bPopup is triggered by a DDL when an item is selected. Now, I want to reset my DDL to value 0 when the user clicked outside of popUp.

PS: Im able to close my popUp, unless I click for two times on html page I cant able to capture that click event.

$("html").click(function () {

    if ($('#bPopup').is(":visible")) {
        $('#ddl').val('0');
    }

});

Upvotes: 0

Views: 598

Answers (2)

Sweetz
Sweetz

Reputation: 342

 $(document).mouseup(function (e) {
    var container = $(your container selector);
    if (!container.is(e.target) // if the target of the click isn't the container...
    &&
    container.has(e.target).length === 0) // ... nor a descendant of the container
                                {
                                    container.hide();
                                }
});

try this code

Upvotes: 2

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

You can use event.target to indentify the clicked element, see below code :

$("html").click(function (e) {

    // check if id of clicked element is not bPopup
    if(e.target.id!="bPopup")
    {
        $('#ddl').val('0');
     }
    if ($('#bPopup').is(":visible")) {
        $('#ddl').val('0');
    }

});

Upvotes: 0

Related Questions