Using colons in querySelectorAll ()

I'm trying to use the querySelectorAll() method to capture links on web pages, but I want to ignore links starting with "javascript:", or use a different protocol like "itpc: //"

Is it possible to include them in the pseudo-selector "not ()"?

 document.querySelectorAll("a:not([href^=javascript]):not([href^=itpc])"); //works document.querySelectorAll("a:not([href^=javascript:]):not([href^=itpc://])"); //doesn't work 

Despite the fact that the first method works fine on the current page, there is no guarantee that it will work on every page on which I will use it, so I would really like to find this colon.

+4
source share
1 answer

Based on spec , by turning the values ​​you want to target, strings will work:

 document.querySelectorAll("a:not([href^='javascript:']):not([href^='itpc://'])"); 

The problem with the current version is that if you do not use quotation marks, the values ​​must conform to the restrictions placed on identifiers that they are not.

+11
source

Source: https://habr.com/ru/post/1402150/


All Articles