Cosmi
Cosmi

Reputation: 119

jQuery - stop mouseover loop

I need to stop the mouseover event if a condition is true and I don't really now how. I 've made this:

$('body').mouseover(function() {
    if ($('span.done').length > 0) {
        alert('done!');
    }
});

after the alert() is called, the mouseover should stop, and stop calling the allert. Any help is much appreciated. Thanks.

Upvotes: 0

Views: 433

Answers (2)

septemberbrain
septemberbrain

Reputation: 1008

Look at jquery .one() event handler. Doc is here.

Upvotes: 1

Esailija
Esailija

Reputation: 140230

$('body').on("mouseover.done",function() {
    if ($('span.done').length > 0) {
        $("body").off("mouseover.done");
        alert('done!');
    }
});

Upvotes: 1

Related Questions