How to exclude specific class names in querySelectorAll()?

后端 未结 3 1132
悲哀的现实
悲哀的现实 2021-02-05 00:50

How can I exclude tag elements that have a specific class name?




document.querySelectorAll(\'span         


        
相关标签:
3条回答
  • 2021-02-05 00:58

    Use :not CSS pseudo-class:

    document.querySelectorAll('span.test:not(.asd)');
    
    0 讨论(0)
  • 2021-02-05 01:05

    Use the CSS's negation pseudo-selector, :not():

    document.querySelectorAll('span.test:not(.asd)');
    

    The negation pseudo-class, :not(X), is a functional notation taking a simple selector (excluding the negation pseudo-class itself) as an argument. It represents an element that is not represented by its argument.

    0 讨论(0)
  • 2021-02-05 01:17

    Element by tagName and ignore or exclude element that have a specific class:

    document.querySelectorAll(`svg,div:not([class*="background"]`)
    
    0 讨论(0)
提交回复
热议问题