How to use jQuery to select ids not in a specific class
I have a jQuery script that selects all IDs with "phone" in them. However, I have a small part that should NOT select them if they are in a class.
What I have, as I understand it, is this:
$("[id*='Phone']:not('referencePhones')").doSomething();
What am I missing?
.referencePhones is the parent class. i.e:
div class="referencePhones"
span id="Phone"
+2
source to share
4 answers
$("[id*='Phone']").parent(":not('.referencePhones')").css("color","red");
and your code looks something like this:
<div class="referencePhones">
<span id="Phone2">phone2</span>
<span id="Phone3">phone3</span>
<span id="Phone4">phone4</span>
<span id="Phone5">phone5</span>
</div>
<div class="zzz">
<span id="Phone6">phone6</span>
<span id="Phone7">phone7</span>
<span id="Phone8">phone8</span>
<span id="Phone9">phone9</span>
</div>
+3
source to share