Dom_02 Search and element manipulation

Source: Internet
Author: User
Tags tag name

1. Find the surrounding elements by the relationship between nodes;

2. Search HTML properties: ① by ID: var Elem=document.getelementbyid ("id"); Find an element that must be called by document; ② by tag name: Var elems= Parent.getelementsbytagname ("tag name"), finds the specified tag name element under the specified parent element, finds all descendant nodes, ③ by Name property: Var elems=parent.getelementsbyname ("name" ); Specifies the element under the parent element that looks for the specified name attribute; ④ by class: Var elems=parent.getelementsbyclassname ("class"); Specifies the element under the parent element that finds the specified class attribute; * (* If getelementsxxx is not found, return to the empty set "";);

3. Finder: ① only find one element that meets the selector requirements: var elem=parent.queryselector ("selector"), ② find multiple elements that meet the selector requirements: Var elem= Parent.queryselectorall ("selector"); Returns an empty collection "";

4, find GetXXX and Queryselector difference: GetXXX: Code cumbersome, but the implementation of high efficiency; Queryselector: The code is simple, the return content contains the complete set of attributes, so the execution efficiency is slow;

5, Operation content: ①elem.innerhtml: Start tag to end the HTML content of the tag, ②elem.textcontent: Start tag to end the text content of tag (do not contain HTML tag);

6, the core of the Operation attribute DOM: (omnipotent); ① Access Attribute Node object: var node=elem.attributes "i/" property name "" Or: Var node=elem.getattributenode ("Property name") ; property value: Node.value;② Gets the property value: Var value=elem.getattribute ("Property name"), ③ Modify property value: Elem.setattribute ("Property name", "value") ; ④ Remove attribute: Elem.removeattribute ("attribute name"); ⑤ determines whether the specified attribute is included: var bool=elem.hasattribute ("attribute name");

7. HTML DOM for manipulating attributes: Encapsulates HTML standard attributes into an element object: Elem. Attribute name; * (* access to HTML standard attributes only);

8. Custom properties of Operation properties: ① core DOM Magnum; ②HTML5: When defining a custom property, data-Property name = "Value"; When reading a custom attribute, Elem.dataset. property name;

9, property and attribute difference: ①attribute: Explicitly written in the start tag; GetAttribute can only get the attribute value explicitly defined on the page; ②property: Save in Memory object; * (* custom attribute not);

10, no attribute value attribute: Get check box to select the state of the checked, cannot use getattribute, must use elem.checked;

Dom_02 Search and element manipulation

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.