简体   繁体   English

如何在多个类作为一个类的jQuery中使用not选择器

[英]How to use not selector in jquery with multiple classes as one class

I have in my HTML div with one class tag and one with 2 classes that look like one class. 我的HTML div中有一个类标记,一个有2个类,看起来像一个类。

<body>
    <div class="ad-container left">
    <div class="ad-container">
    <div class="mobile-ad larger">
    <div class="mobile-ad">
</body>

Whats the proper way to use the not selector in jQuery to support all 4 div's and not ignore anything else in body. 什么是在jQuery中使用not选择器来支持所有4 div且不忽略正文中其他内容的正确方法是什么?

I currently have 我目前有

$('body:not(.ad-container,.ad-container.left,.mobile-ad.larger,.mobile-ad)')

It seems to work without any problems. 它似乎没有任何问题。

But something tells me I need to split the left and larger classes into seperate elements by comma. 但是有些事情告诉我,我需要用逗号将左类和较大的类拆分为单独的元素。

Something like this 像这样

$('body:not(.ad-container,.left,.mobile-ad,.larger)')

Here is the full code: 这是完整的代码:

     $(function () {
        $('body:not(.ad-container,.ad-container.left,.mobile-ad.larger,.mobile-ad)').on('selectstart', function (event) {
            event.preventDefault();
        });
    });

It's used to disable the left double click selection but still be able to click on ads. 它用于禁用左键双击选择,但仍然可以点击广告。 Which one should I use? 我应该使用哪一个?

我最终使用

$('body :not(.ad-container, .mobile-ad)') 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM