TheKid
TheKid

Reputation: 349

jquery function dont reflect the class change made my another event

hover class anchor alerts it's title value on hover and when on nohover class anchor, add nopop class to the anchor with hover class. and thus to stop hover alert as it is expected to alert only on hover class without nopop class.

<a class="hover" title="bla bla bla">hover alert</a><br/>
<a class="nohover">stop hover alert</a>

please where I went wrong here

$(function () {

    $(".hover:not(.nopop)").hover(function () {
        alert($(this).attr("title"));
    })

    $(".nohover").hover(function () {
        $(".hover").addClass("nopop");
    });    
});   

Fiddle http://jsfiddle.net/z4BHJ/8/

Upvotes: 1

Views: 64

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

You need to use a delegated handler since the selector is dynamic

$(function () {
    $(document).on('mouseenter', '.hover:not(.nopop)', function () {
        alert($(this).attr("title"));
    })

    $(".nohover").hover(function () {
        $(".hover").addClass("nopop");
    });
});

Demo: Fiddle

Upvotes: 3

Related Questions