Reputation: 3682
I have some div tag below:
<div class="magazine"></div>
<div class="newsletter"></div> // I need to take this div
<div class="may-moon"></div>
If I needed div with class start with "ma", I would use $('div[class^="ma"]')
, but what is opposite? thanks.
Upvotes: 5
Views: 1677
Reputation: 8171
You need to use :not() Selector
for this. because there is no exact opposite selector exist of [^=]
and *
in jquery.
:not() Selector - Selects all elements that do not match the given selector.
See more about Jquery selectors
There a opposite selector exist !
-
Attribute Not Equal Selector [name!="value"] - Select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value.
but use of this !
selector, you need to provide full-name of class.
$('div[class!="magazine"][class!="may-moon"]')
Upvotes: 0
Reputation: 1317
You can use the negative filtering function "not" like this: $('div').not('[class^="ma"]')
, or the negative selector ":not" like this: $('div:not([class^="ma"])')
(as pointed by Karl-André Gagnon)
Upvotes: 3
Reputation: 33870
The opposite would be to use jQuery :not():
$('div:not([class^="ma"])')
Upvotes: 14