开发者

queryselectorAll - find an element with more than one matching class

Using the JS queryselectorall method is it possible to select an elemnent of a particular tag name with 2 matching classes.

E.g. I have an element

<a class="c开发者_StackOverflow社区lassOne classTwo"></a>

using queryselectorall I can select on one classname:

document.querySelectorAll("a.classOne");

how could this be extended so I can find all a tags with classOne AND classTwo?

document.querySelectorAll("a.classOne classTwo"); as expected doesn't seem to work

Thanks in advance


The same way you would in CSS:

document.querySelectorAll("a.classOne.classTwo"); 

example: http://jsfiddle.net/gcf6w/6/


Just add a dot..

document.querySelectorAll("a.classOne.classTwo")   


This is a sample query selector command that fetches all youtube src URL in one command.

document.querySelectorAll('yt-img-shadow.style-scope.ytd-thumbnail.no-transition  img').forEach(e=>console.log(e.src))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜