template id function can generate invalid tag ids
template toggleVisibility( initialText: String ){ <a onclick="$( '#123' ).show(); $(this).hide();"> output( initialText ) </a> <div id="123" style="display:none;"> elements </div> } page root { toggleVisibility("test"){"output"} }
id
can generate identifiers starting with a numberThe 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:
https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute
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
Submitted by Danny Groenewegen on 31 March 2021 at 14:50'#123' is not a valid selector
when usingdocument.querySelector("#123")
Log in to post comments