How to form a Query Select That Works With Ands an

2019-07-29 07:33发布

I have a class defined HtmlElements as follows:

<div class="GM BOLTA 2016" >
<div class="GM BOLTB 2016" >
<div class="GM BOLT 2015" >
<div class="FORD BOLT 2016" >

I want to be able to make query selectors against this and specifically, I'd like to know all div tags that have GM and also have anything that starts with BOLT and is not 2015.

I'm thinking something like

[GM][^BOLT]!2015 

but obviously wrong.

1条回答
Lonely孤独者°
2楼-- · 2019-07-29 08:02

I'd like to know all div tags that have GM and also have anything that starts with BOLT and is not 2015.

Plain Javascript:

var matches = document.querySelectorAll('.GM, [class^="BOLT"]:not(.2015)');

jQuery:

$('.GM, [class^="BOLT"]:not(.2015)')
查看更多
登录 后发表回答