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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With