QuerySelectorAll () in IE8 _ javascript skills

Source: Internet
Author: User
In the new features of IE8, I mentioned that querySelector () and querySelectorAll () methods are supported. I won't talk about how to use them here. I just recorded a problem I encountered during usage. 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 $, ^.
Remember to declare it on the HTML page.

Test code:


The Code is as follows:







This is a sample warning
This is a sample error



This is another sample warning
This is another sample error


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.