6
\$\begingroup\$

What is the shortest selector (by character count) to select ALL html elements on a web page, without using asterisk (*)? Some examples are the following:

a,:not(a) /*9 chars*/

:nth-child(n) /*12 chars*/

:link,:not(:link) /*17 chars*/
\$\endgroup\$
5
  • 9
    \$\begingroup\$ In Firefox at least, there's no HTML · element (it's an illegal tag name), so could you shorten a,:not(a) to :not(·)? \$\endgroup\$
    – Neil
    Commented Oct 28, 2023 at 19:37
  • 1
    \$\begingroup\$ @Neil That's interesting. What is the significance of the middle dot character (U+00B7)? Was it just a random character you chose? \$\endgroup\$ Commented Oct 28, 2023 at 19:43
  • 1
    \$\begingroup\$ It was the first one I found where document.createElement threw an error but :not did not. \$\endgroup\$
    – Neil
    Commented Oct 28, 2023 at 19:44
  • 1
    \$\begingroup\$ @Neil After playing around with some more special symbols, I was curious to know if there were any "standard" symbols could be typed from a keyboard. The only symbol I could get to work that exists on a keyboard is a double backslash: :not(\\). I wonder why and how that works, but something like :not(^) does not. \$\endgroup\$ Commented Oct 28, 2023 at 20:07
  • \$\begingroup\$ @Neil Update: other characters also work when preceded by a backslash, for example :not(\*) and :not(\#) \$\endgroup\$ Commented Oct 28, 2023 at 20:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.