admin管理员组文章数量:1307053
Let's say I want to find all div
elements and span
inside p
.
Is it possible to get all what I want in a single querySelectorAll
invocation?
Conceptually it should be something like document.querySelectorAll("div | p span")
(where | means or).
Let's say I want to find all div
elements and span
inside p
.
Is it possible to get all what I want in a single querySelectorAll
invocation?
Conceptually it should be something like document.querySelectorAll("div | p span")
(where | means or).
1 Answer
Reset to default 49Yes. You can use the same logical operators allowed in CSS:
OR: chain selectors with commas
document.querySelectorAll('div, p span');
// selects divs, and spans in ps
AND: chain selectors without whitespace
document.querySelectorAll('div.myClass');
// selects divs with the class "myClass"
NOT: :not()
-selector
document.querySelectorAll('div:not(.myClass)');
// selects divs that do not have the class "myClass"
本文标签: javascriptCan I put logical operators in documentquerySelectorAll If sohowStack Overflow
版权声明:本文标题:javascript - Can I put logical operators in document.querySelectorAll? If so, how? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737600716a1998304.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
document.querySelectorAll("p div, p span")
– Rajaprabhu Aravindasamy Commented Apr 11, 2016 at 9:36span
elements insidep
and alldiv
elements throughout the DOM. – Rajaprabhu Aravindasamy Commented Apr 11, 2016 at 9:37