JS Get Node method

Source: Internet
Author: User

Old version Get node
1. Get body
Console.log (document.body);

2. Get img
Console.log (document.images);

3. Get a tag
Console.log (document.links);

4. Get a label containing the name attribute
Console.log (document.anchors);

5. Get Form Label


Console.log (document.forms);

Methods to get Nodes
New version gets node method: DOM2
1, through the ID gets, can be given a variable to save (in parentheses write ID name)


Let A = document.getElementById ("box");
Console.log (a);
2. Get through Class (get an array)


Console.log (Document.getelementsbyclassname ("1"));
3, obtained by the tag name (gets the array)


Console.log (document.getElementsByTagName ("div"));
4, obtained by the Name property (Gets the array)


Console.log (Document.getelementsbyname (2));

HTML5 Get Node method
1. Gets the first tag that satisfies the selector (the CSS selector is written in parentheses)


Console.log (Document.queryselector (". Box1>p"));


2. Get an array (the CSS selector is written in parentheses)


Console.log (Document.queryselectorall (". Box1>p"));

JS Get Node method

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.