How to use jQuery to select IDs not in specific class
I have a jQuery script that selects all IDs with 'Phone' in them. However, I have a small part that needs to NOT select them if they are in a class.
What I have, according to the way I understand it is this:
$("[id*='Phone']:not('referencePhones')").doSomething();
What am I missing?
.referencePhones is a parent class. ie:
div class="reference开发者_如何转开发Phones"
span id="Phone"
get rid of your internal quotes:
$('someElement[id*=Phone]:not(.referencePhones)').doSomething();
EDIT
$('span[id*=Phone]').parent('div:not(.referencePhones)').doSomething();
A dot?
$("[id*='Phone']:not(.referencePhones)").doSomething();
^
$("[id*='Phone']").parent(":not('.referencePhones')").css("color","red");
and your code looks something like the following right?
<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>
The OP is asking to select the spans with ids containing "phone" as long as they are not contained in a div with class "referencePhones." All of the solutions that use parent() return the parent div and not the span.
The following selector returns the spans:
$('div:not(.referencePhones) span[id*="Phone"]')
精彩评论