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 un开发者_JS百科til now is $(this:not('.someClassName')).append("<b></b>")
but of course it's not working.
What can I do?
Cheers.
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.
精彩评论