最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - javascript - how to implement `not` in querySelector? - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Sep 12, 2017 at 7:07 shishir 8493 gold badges11 silver badges27 bronze badges asked Sep 12, 2017 at 6:58 fweidemann14fweidemann14 1,9933 gold badges14 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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

:not([disabled])
发布评论

评论列表(0)

  1. 暂无评论