user34537
user34537

Reputation:

Best way to ignore less specific click event with jquery?

I have the code below. The main code is in the 2nd function however the first is called which is interfering with the more specific a.One code.

Whats the best way to not run code in the first function if the div i click is a .main .a.One event?

$('.main .a').live('click', function () {
    alert('first');
    //2 lines of code
});
$('.main .a.One').live('click', function () {
    alert('second');
    //lots of logic
});

Upvotes: 0

Views: 78

Answers (1)

Fábio Batista
Fábio Batista

Reputation: 25270

$('.main .a').live('click', function () {
    if (!$(this).hasClass('One'))
    {
        alert('first');
        //2 lines of code
        return;
    }

    alert('second');
    //lots of logic
});

Upvotes: 1

Related Questions