Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery on click select element if it's not in the specific class

I am trying to do this but no luck so far does anyone know how to select an element on click but not include elements in specific div like .box and all content inside that div .box

small update: thank you for responses, but if i am using :not or hasClass it won't assure that elements inside that foo won't be selected. like:

<div class=foo>this won't be selected <span>this will</span></div>

like image 477
Dejan Avatar asked Nov 28 '10 18:11

Dejan


1 Answers

You could use the hasClass() method:

$('a').click(function() {
    if (!(this).hasClass('foo')) {
        // the clicked element doesn't have the foo class        
    }
    return false;
});
like image 112
Darin Dimitrov Avatar answered Sep 30 '22 20:09

Darin Dimitrov