问题
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