Document. querySelector and querySelectorAll methods

Source: Internet
Author: User

QuerySelector and querySelectorAll are new query interfaces provided by W3C. Their main features are as follows:

1. querySelector returns only the first matching element. If no matching item exists, null is returned. 2. querySelectorAll returns a set of matched elements. If no matching item exists, an empty nodelist (node array) is returned ). 3. The returned results are static. Subsequent changes to the document structure will not affect the previous results. Both methods can accept three types of parameters: id (#), class (.), and label, much like the jquery selector.
Var obj = document. querySelector ("# id"); var obj = document. querySelector (". classname"); var obj = document. querySelector ("div ");

Var elements = document. querySelectorAll ("# score> tbody> tr> td: nth-of-type (2)"); var elements = document. querySelectorAll ("# id1, # id2 ,. class1, class2, div a, # list li img ");

Document. querySelector and querySelectorAll methods

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.