Select parent if it hasn't a certain class

I understand that using


.parent(".class")

I can select the parent of the current element if it (the parent) has a class named “class”. How can I select parents that don’t have a certain class? Also, how can I select parents that don’t have more than one class? Does the .parent() method allow to do this?

I need to add a class only to elements whose parents don’t have a certain class to avoid conflicts.

You should be able to use something like

if (!$(this).parent().hasClass('className')) {
    // Do something...
}

Yeah, I thought about this too, maybe it’s the easiest way. I was just wondering if I could just use the .parent() method to avoid having an if statement.

.parent(‘:not(.class)’)
.parent(‘:not(.class1, .class2)’)

Great, thank you very much!!