method of creating, inserting, deleting, querying, replacing DOM nodes (JS implementation)

Source: Internet
Author: User

1. Create element node: createelement

Usage: document.createelement ("P");//create P tag;

Create text node: createTextNode;

Usage: document.createTextNode ("txt");//create text label;

2. Insert node: appendchild: Called on the element node to be inserted, he inserts the specified node to make it the last child node of that node.

InsertBefore: Inserts a new element before the existing element;

InsertAfter: Inserts a new element after the existing element;

3. Delete node: removechild; Removes a node from the document tree (first the parent node to delete the node is deleted);

Usage: var para1=document.getelementbyid ("P1");

Para1.parentNode.removeChild (PARA1);

4, replace node: replacechild; replace one node with another (the parent node of the node to be replaced is first found, replaced with the parent node);

method of creating, inserting, deleting, querying, replacing DOM nodes (JS implementation)

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.