views:

22

answers:

1

I'm new to JQuery, i suppose that's really simple but I can't find the right selector. I tried with this code:

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

but it doesn't work, in fact it seems to suck all the cpu time. Can you help me? Thanks!

+2  A: 

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

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

You can test the selector out here.

Currently you're trying to bind a click event to everything that's not an anchor with one of those words in it's href attribute...every element which is very expensive both to check and to bind, this instead binds to anchors and only then if their href doesn't contains either of those words.

Nick Craver
thanks, it works!
astorcas