Reputation: 2601
Trying to assemble a rather complex jQuery selector here, and having trouble.
Essentially, I'm trying to grab all anchors that that 1) do not have a "rel" of "facebox", and OR 2) do not have an "href" that begins with "mailto".
This is what I've been trying to do:
$('a[rel!=facebox], a[href!^="mailto"]')
Small variations of this don't seem to work. Is there some better way of going about this?
These selectors seem to work individually, but not when sitting consecutively in the same selector:
$('a:not([rel=facebox]), a:not([href^=mailto])')
Final solution: We have a winner!
$('a:not([rel=facebox],[href^=mailto])')
Upvotes: 24
Views: 21331
Reputation:
Alright Mr. Jeremy Ricketts. Jquery has messed up your head. You are trying to chain selector logic...kind of like how jQuery chains methods. In your second selector (a[href!^="mailto"]
) you are trying to say...NOT things that contain THIS attribute. What you are saying is "Search for all things that are not mailto" and "Search for all things that contain mailto". It's like light filters...if you filter red light...and throw a yellow light filter on top...you are not filtering for orange light...you just filtered out EVERYTHING (sorry for the stretch of an analogy). So what you are trying to do is use the pseudo selector :not.
Like this - $(a:not([href^=mailto:])).whateverJqueryMethodYouWant();
EDIT:
Well now that you have spec'd out the question properly...you can do it like this - $(a:not([href^=mailto:] , [rel=facebox])).whateverJqueryFunctionYouWant();
Upvotes: 3
Reputation: 78104
You want the :not selector
$("a:not([rel=facebox],[href^=mailto])");
EDIT: I stole your answer for correctness
Upvotes: 55