JavaScript removes HTML node operations

Source: Internet
Author: User


Deleting a node on an HTML page is similar to adding a paragraph in the Add node before the specified attachment point, adding the paragraph to the specified attachment point before the code is document.body.insertBefore (Newgraf, Docform), removed as document.body.removeChild (deletenode) can do it. The removechild method is used to remove the element inside the body field.


Look at a code to introduce it.

If there is a code below, the content has four paragraphs.


Now to delete the paragraph content, how to implement the Deletenodes method?

It's simple, two lines of code are done.

      var deletenode =document.getelementsbytagname ("P") [0];      Document.body.removeChild (Deletenode);

var deletenode =document.getelementsbytagname ("P") [0];

Gets the content of the paragraph to be deleted, document.getElementsByTagName ("P") [0] is the first P-label content within the Body label field.

document.body.removeChild (deletenode);

Remove the node information you want to delete from the page, using the RemoveChild method.

If the paragraph has an ID, then you can directly use the getElementById method to specify the object to be deleted, no longer using the getElementsByTagName method to get to the object collection, and then the array subscript to specify the Delete object.

In our example, document.getElementsByTagName ("P") [0] is removed, and other paragraphs, such as document.getElementsByTagName ("P") [3], can also be deleted, such as real-life paragraph information.


JavaScript removes HTML node operations

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.