How to Select Element That Does Not have Specific Class

前端 未结 5 2032
别跟我提以往
别跟我提以往 2020-11-27 14:38

I\'m wondering how to select an element that does not have a specific class using JavaScript, not jQuery.

For example, I have this list:

5条回答
  •  一向
    一向 (楼主)
    2020-11-27 14:48

    You can try the :not() selector

    var completeTask = document.querySelector("li:not(.completed):not(.selected)");
    

    http://jsfiddle.net/UM3j5/

提交回复
热议问题