Javascript-Basic Dom features required

Source: Internet
Author: User

1. Access the elements in the document
Document. getelementbyid ('id'): gets the element of the given ID and uses it as an object.
Document. getelementbytagname ('tagname'): obtains all elements whose tags are named tagnames and stores them in a list similar to an array.

2. Read the attributes, node values, and other node data of the element.
Node. getattribute ('attribute'): gets the value of attribute.
Node. getattribute ('attribute'. 'value'): Set the attribute value to value.
Node. nodetype: Read node type (1 = element, 3 = text node ).
Node. nodename: Read the node name (element name or # textnode ).
Node. nodevalue: read or set the value of a node (text content in the case of a text node ).

3. operations between nodes
Node. previussibling: Get the previous sibling node and save it as a object.
Node. nextsibling: Get the next sibling node and save it as an object.
Node. childnodes: obtains all the child nodes of the object and stores them in a list. For the first and last nodes, you can also use node. firstchild and node. lastchild for short.
Node. parentnode: Get the node containing the node.

4. Create a New Node
Document. createelement (element): to create a new element named element, you must provide an element name in the string format. Document. createtextnode (string): Creates a text node with a node value of string.
Newnode = node. clonenode (bool): Create a newnode node as a node copy (clone ). If the bool value is true, this clone includes cloning of all the child nodes and attributes of the original node. Node. appendchild (newnode): Use newnode as a subnode and add it after all the subnodes of the node. Node. insertbefore (newnode, oldnode): inserts newnode before the node's child node oldnode. node. removechild (oldnode): remove the child node lodnode of the node. node. replaceChild (newnode, oldnode): replace the child node lodnode of the node with the node newnode. element.
Innerhtml: read and write the HTML content of a given element. It is a string that contains the text content of all subnodes and their attributes.

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.