开发者

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

开发者 https://www.devze.com 2022-12-21 12:54 出处:网络
I have this line of code $(this).append(\"<b></b>\") and I want to add a :Not condition to it.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号