neoswf
neoswf

Reputation: 4760

using 'this' and ':not' together in jquery

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.

Upvotes: 2

Views: 73

Answers (1)

cletus
cletus

Reputation: 625307

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.

Upvotes: 6

Related Questions