matzy
matzy

Reputation: 23

a[href*=#]:not([href=#]) - adding class as additional "not" perameter?

I'm using the following line of jQuery for selecting anchor elements:

a[href*=#]:not([href=#])

However, I now have two modules selecting the anchors and interfering with one another. I need this to say

:not([href=#) && (class=fancybox)]

but that's not working. Can anyone tell me how to write this correctly? I want it to ignore dead links and anchors that also have a class="fancybox" (which is how the other module works).

Upvotes: 1

Views: 392

Answers (3)

Karl-André Gagnon
Karl-André Gagnon

Reputation: 33870

You can use a comma separated list with not :

$("a:not(.fancybox, [href='#'])")

The .not() function work the same way.

$("a").not(".fancybox, [href='#']")

The only difference between those two is the readability. Take what you prefer.

Upvotes: 1

Alok Swain
Alok Swain

Reputation: 6519

This should do it:

$("a:not(.fancybox):not([href='#'])")

Upvotes: 3

Amit Joki
Amit Joki

Reputation: 59232

You can use this:

$('a').not('[href="#"]').not('.fancybox');

The above first removes anchors which have # as its href and then removes anchors which have the class fancybox

The same can be done using $("a:not(.fancybox):not([href='#'])") but I would advise against using it, as it disallows jQuery to use more faster querySelector

Upvotes: 1

Related Questions