views:

29

answers:

1

Hi.

I have this line of code $(this).append("<b></b>") and I want to add a :Not condition to it.

The best I could reach until now is $(this:not('.someClassName')).append("<b></b>") but of course it's not working.

What can I do?

Cheers.

+6  A: 

What you're looking for is:

$(this).not(".someClassName").append("<b>");

You could also use a conditional:

if (!$(this).hasClass("someClassName")) {
  ...
}

:not isn't really applicable to this situation unless you wanted to, for example, find all the descendants that don't have a particular class:

$(this).find(":not(.someClassName)")...

or

$(":not(.someClassName)", this)...

These two are equivalent.

cletus
Thank you very much @cletus, you helped me a lot.
Shlomi.A.