When querySelector () or querySelectorAll () is used to find an element similar to name = "2nd_btn", FF, chrome, and IE8 will report an error.
FF, chrome reports the same error, as shown below:
Error: uncaught exception: [Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)" location :"... /test/qsa.html Line: 18 "]
The error message of IE8 is "row: 18". The parameter is invalid.
After removing or modifying the number, the name value starts with a number.
This tells us that when the attribute value of a tag can be customized, the attribute value cannot start with a number or contain uncommon characters such as $, ^.
Make sure to declare it on the HTML page. <! DOCTYPE>.
Test code:
Copy codeThe Code is as follows:
<! DOCTYPE>
<Html>
<Head> <Body>
<Div id = "foo">
<A name = "warns" href = ""> This is a sample warning </a>
<A id = "3err" href = ""> This is a sample error </a>
</Div>
<Div id = "bar">
<A name = "warns" href = ""> This is another sample warning </a>
<A name = "1err" href = ""> This is another sample error </a>
</Div>
<Script>
Var a = document. querySelectorAll ("[name = warns]")
Alert (a. length) // output: 2
Var B = document. querySelector ("[id = 3err]")
Alert (B. tagName) // Error
Var c = document. querySelectorAll ("[name = 1err]")
Alert (c. length) // Error
</Script>
</Body>
</Html>