I have links like this:
<a href="my:stuff">My Link</a>
<a href="other:stuff">My Link</a>
<a href="test:stuff">My Link</a>
<a href="test:stuff">My Link</a>
I want to select links with href that doesn't start with "test"
I've tried the following but they don't seem to work:
$('a[href!^="test"]')
$('a:not([href^="test"]')
I don't want to use $.filter or anything like that. Is there a way to do this with selectors alone?
The !^= selector does not exist. However, your second selector should work after including the closing parentheses ')'.
// Incorrect syntax
$('a:not([href^="test"]')
// Correct syntax
$('a:not([href^="test"])')
or you can choose to use the .not() method instead of the :not() pseudo-selector:
$('a').not('[href^="test"]')
Here's a proof-of-concept of the first (using :not()) and second (using .not()) solutions.
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