LoginSignup
0
0

More than 5 years have passed since last update.

valid selector

Posted at

hashを作ってidの代わりにしようとすると先頭が数字の場合エラーになる。

<li id="1234567"></li> <!--bad-->
<li id="x1234567"></li>
let fn={};
fn.rhash=()=>{return Math.random().toString(36).slice(-8)}
fn.rid=()=>{return 'x'+Math.random().toString(36).slice(-8)}
;
let a=document.querySelector('#'+'x1234567')
console.log(a)
let b=document.querySelector('#'+'1234567')
console.log(b)
//Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#1234567' is not a valid selector.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0