Exclusive CSS selector

后端 未结 3 1864
夕颜
夕颜 2020-12-07 03:53

I am working on a page where the selected item among a list is characterized by NOT having a given class. Something like the following:

3条回答
  •  离开以前
    2020-12-07 04:34

    You can use the :not() pseudo, that's exactly what you need for this job.

    https://developer.mozilla.org/en-US/docs/Web/CSS/:not

    So all you have to do is

    document.querySelector(".a:not(.b)")
    

    But also consider using jQuery, like

    $(".someclass").not(".another")
    

    Stansard querySelector is faster, jQ is more readable.

提交回复
热议问题