This is probably pretty simple.
I want to select all elements of a given class thisClass
, except where the id is thisId
.
i.e. something equivalent to (where -/minus implies remove):
$(".thisClass"-"#thisId").doAction();
This is probably pretty simple.
I want to select all elements of a given class thisClass
, except where the id is thisId
.
i.e. something equivalent to (where -/minus implies remove):
$(".thisClass"-"#thisId").doAction();
I'll just throw in a JS (ES6) answer, in case someone is looking for it:
Update (this may have been possible when I posted the original answer, but adding this now anyway):
This gets rid of the
Array.from
usage.document.querySelectorAll
returns aNodeList
.Read here to know more about how to iterate on it (and other things): https://developer.mozilla.org/en-US/docs/Web/API/NodeList
You could use the .not function like the following examples to remove items that have an exact id, id containing a specific word, id starting with a word, etc... see http://www.w3schools.com/jquery/jquery_ref_selectors.asp for more information on jQuery selectors.
Ignore by Exact ID:
Ignore ID's that contains the word "Id"
Ignore ID's that start with "my"
Or take the .not() method
https://api.jquery.com/not/
Use the :not selector.
If you have multiple ids or selectors just use the comma delimiter, in addition:
(".thisclass:not(#thisid,#thatid)").doAction();
$(".thisClass[id!='thisId']").doAction();
Documentation on selectors: http://api.jquery.com/category/selectors/
Using the
.not()
method with selecting an entire element is also an option.This way could be usefull if you want to do another action with that element directly.