views:

228

answers:

4

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="referencePhones"
  span id="Phone"
+4  A: 

A dot?

$("[id*='Phone']:not(.referencePhones)").doSomething();
                     ^
Reinis I.
Nope. Tried that. That class is a parent. .referencePhones #Phones
Mikecancook
+6  A: 

get rid of your internal quotes:

$('someElement[id*=Phone]:not(.referencePhones)').doSomething();

EDIT

$('span[id*=Phone]').parent('div:not(.referencePhones)').doSomething();
Jason
Still no love. ;o(
Mikecancook
you have to use the filter() together with is(!referencePhones); when i will have a moment ill write you the selector
adardesign
with your edited new information, things will change...
Jason
I thought I was being perfectly clear, so much for thinking. Think it's time for me to pick up the jQuery in Action book!
Mikecancook
+2  A: 
$("[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>
easement
i know you accepted this answer, and while it "works" it is not the best solution. i'm not trying to play sour grapes, but my solution is a lot faster because it will only search for `spans` with the id of phone rather than every single element on the page, as this solution will. just saying.
Jason
What Jason says is true.
easement
A: 

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"]')
Keith Morgan