Home>Article>Web Front-end> How to delete node in javascript

How to delete node in javascript

藏色散人
藏色散人 Original
2021-03-30 14:34:45 6019browse

Javascript method to delete a node: 1. Use the remove() method to delete all elements on the parent node, including all text and child nodes; 2. Use the removeChild() method to delete a child node on the parent node.

How to delete node in javascript

The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

Method 1: Use remove() to delete a node

The remove() method can be used to delete all elements on the parent node, including all text and child nodes.

Example: Delete all child nodes li on the ul node

    
  • Get Up in Morning
  • Do some exercise
  • Get Ready for school
  • Study Daily
  • Do homework

Rendering:

How to delete node in javascript

Method 2: Use removeChild ()Delete node

removeChild() method is used to delete a child node on the parent node.

Example: Delete all child nodes li on the ul node

    
  • Get Up in Morning
  • Do some exercise
  • Get Ready for school
  • Study Daily
  • Do homework

Rendering:

How to delete node in javascript

[Recommended learning:js Basic tutorial

The above is the detailed content of How to delete node in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn