JQuery selector: href attribute contains neither word1 nor word2

I am new to jQuery, I suppose it is really simple, but I cannot find the correct selector. I tried with this code:

$(":not(a[href=word1],a[href=word2]").click(function() { ... do something } 

but it will not work, it actually seems to suck the processor all the time. Can you help me? Thanks!

+6
jquery jquery-selectors
source share
1 answer

Here's a much more efficient version that first narrows it down to binding:

 $("a:not([href*=word1],[href*=word2])").click(function() { //do something }); 

Here you can check the selector .

You are currently trying to associate the click event with everything that is not an anchor with one of these words in it with the href attribute ... every element that is very expensive both for verification and for binding is attached to anchors instead, and only then if their href does not contain any of these words.

+18
source share

All Articles