template toggleVisibility( initialText: String ){
  <a onclick="$( '#123' ).show(); $(this).hide();">
    output( initialText )
  <div id="123" style="display:none;">
page root {

id can generate identifiers starting with a number

The example above works in jquery, it seems to call getElementById directly if the selector matches ^#([\w-]+))$ (https://github.com/jquery/jquery/blob/main/src/core/init.js#L15, https://github.com/jquery/jquery/blob/main/src/core/init.js#L76)

Some documents state that it’s valid:


There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.

On the other hand the browser can report '#123' is not a valid selector when using document.querySelector("#123")

Submitted by Danny Groenewegen on 31 March 2021 at 14:50

Log in to post comments