javascript - how to implement `not` in querySelector?

放肆的年华 提交于 2019-12-25 18:42:15

问题


Quick question: let's say you have 2 different types of <button>,
First one looks something like this: <button class="test">
Second looks like this: <button class="test" disabled="disabled">.

Now, how can one achieve a selection of the disabled button without selecting the activated button? Cause if you go by class, querySelector would get both of them. Is there a way to implement some kind of logic into the selection made by querySelector?

Something like this maybe -> "select button with class 'test' AND NOT attribute 'disabled'"?

Thanks in advance.


回答1:


The same way you do it in any other selector. With the negation pseudo-class.

:not([disabled])


来源:https://stackoverflow.com/questions/46169897/javascript-how-to-implement-not-in-queryselector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!