Delete node (removechild ())

Source: Internet
Author: User

Remocechild (): The method removes a child node from a given element:

Reference = element.removechild (node);

The return value of this method is a reference pointer to a child node that has been deleted.

When a node is deleted by the RemoveChild () method, all child nodes contained by the node are deleted at the same time.

In the following example, the id attribute value is content and the element containing this id attribute value is an element of fineprint, and we will use the RemoveChild () method to delete the FinePrint element from the content element:

var container = document.getElementById ("content"); var message = document.getElementById ("FinePrint"); contianer.removechild (message);

If you want to delete a node, but do not know which one the parent node is in, the ParentNode property can be used:

var message = document.getElementById ("FinePrint"); var container = message.parentnode;container.removechild (message);

If you want to move a node from one part of the document to another, you do not have to use the RemoveChild () method, and the AppendChild () and InsertBefore () methods automatically remove the node before inserting it into the new position.

Delete node (removechild ())

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.