I'm trying to use the querySelectorAll()
method to grab links in web pages, but I want to ignore links that begin with "javascript:" or use another protocol like "itpc://"
Is there any way to include these in a "not()" pseudo selector?
document.querySelectorAll("a:not([href^=javascript]):not([href^=itpc])"); //works
document.querySelectorAll("a:not([href^=javascript:]):not([href^=itpc://])"); //doesn't work
Even though the first method works fine on the current page, there's no guarantee that it will work on every page I'll be using it on, so I'd really like to be able to detect that colon.
Based on the spec, turning the values you want to target into strings will work:
document.querySelectorAll("a:not([href^='javascript:']):not([href^='itpc://'])");
The problem with your current version is that unless you use quotes the values have to conform to the restrictions placed on identifiers, which they do not.
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