asankasri
asankasri

Reputation: 486

JQuery + Bind event for all the elements except a certain div and its all elements

I need to bind mouseover, mouseout and click events for the all the elements but except a certain Div and it's child elements.

<html>
    <head></head>
    <body>
        <div>
        <!-- page content goes here -->
        </div>
        <div class="popup">Popup content goes here</div>
    </body>
</html>

I can bind the events for all the elements as below.

$(document).ready(function () {
    $(this).find("body *").mouseover(function(e){
        // do something
    }).mouseout(function(e){
        // do something
    }).click(function(e){
        // do something
    });
});

I tried in several ways to ignore the content of ".popup" div. But it wasn't successful.

Appreciate your solution. Thank you!

Upvotes: 0

Views: 2443

Answers (2)

Black Ops
Black Ops

Reputation: 374

try:

    $(document).ready(function () {
    $(this).find("body *").not(':has(> .yourclassyoudontwant)').mouseover(function(e){
        // do something
    }).mouseout(function(e){
        // do something
    }).click(function(e){
        // do something
    });
});

Upvotes: 0

Rituraj ratan
Rituraj ratan

Reputation: 10378

$(this).find("body *").not(".popup").mouseover(function(e){
        // do something
    }).mouseout(function(e){
        // do something
    }).click(function(e){
        // do something
    });

but you must try below code in document reday $(this) not work

$(document).ready(function () {
    $("body *").not(".popup").mouseover(function(e){
            // do something
        }).mouseout(function(e){
            // do something
        }).click(function(e){
            // do something
        });
});

reference .not()

Upvotes: 1

Related Questions