RemoveChild () function usage in JavaScript and removechild

Source: Internet
Author: User

RemoveChild () function usage in JavaScript and removechild

The removechild function can delete the specified child element of the parent element.

If this function successfully deletes a subnode, the deleted node is returned. Otherwise, null is returned.

Syntax structure:

FatherObj. removeChild (childrenObj)

Parameter description:

1. fatherObj: The Element Object of the child element to be deleted.
2. childrenObj: The child element object to be deleted.

Note:

In Firefox, Google, and IE8 browsers, the blank content is also a text node, but the blank text nodes are ignored in IE8 and IE8 browsers, for more information, see section 1 "how to obtain child nodes and parent nodes of an element" in javascript.

Code example:

Instance 1:

<! DOCTYPE html> 

The above code deletes the second li element in the child element of the box.

Example 2:

<! DOCTYPE html> 

The code above selects the element node from all the child nodes in the box, puts the element node into the array, and then deletes the second element node.

Summary:

RemoveChild ()

This function is used to obtain the parent element of an element and delete it. Syntax format: parent. removeChild (child );

Sometimes we want to delete it without involving the parent element. However, DOM is a mechanism that requires clear elements and parent elements to be deleted. You can also delete the elements to be deleted. You can use the parentNode attribute to find the parent element:

var child=document.getElementById(p1);child.parentNode.removeChild(child);

Note: jquery also has functions that correspond to removeChild: remove () and empty ()

Remove (): deletes both the user and the child element.

Empty (): deletes child elements.

Articles you may be interested in:
  • Precautions for using javascript removeChild
  • Js removeChild blind-eye Error
  • Memory leakage caused by javascript removeChild
  • How to remove javascript node removeChild ()
  • Js uses the removeChild method to dynamically Delete div elements
  • Example of using javascript to delete an element node removeChild ()
  • Javascript removeChild () method for deleting nodes and subnodes

Related Article

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.