JavaScript removechild () Functional usage detailed _javascript tips

Source: Internet
Author: User

The RemoveChild function can delete the specified child elements of the parent element.

If this function deletes a child node successfully, it returns the node that was deleted, otherwise null is returned.

Syntax structure:

Fatherobj.removechild (Childrenobj)

Parameter explanation:

1.FATHEROBJ: The element object to delete the child element.
2.CHILDRENOBJ: The child element object to be deleted.

Special Note:

In Firefox, Google, and IE8 browsers, white space is also a text node, but the blank text node is ignored in IE8 and IE8 browsers, and you can see how JavaScript gets the child node and the parent node section of the element.

Code instance:

Example one:

<! DOCTYPE html>
 
 

The above code can delete the second Li element in the child element of box.

Example two:

<! DOCTYPE html>
 
 

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

Summarize:

RemoveChild ()

This function is to get the element's parent element and delete it. The grammatical form is: parent.removechild (child);

Sometimes we want to delete without involving the parent element. But Dom is the mechanism that must be explicit about the element and the parent element before it can be deleted. When we go to the element to be deleted, we can also delete, using its ParentNode property 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 (): means to delete both itself and the child elements

Empty (): Is to delete child elements

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.