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