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

How to delete nodes in javascript

青灯夜游
青灯夜游Original
2021-04-01 15:24:2312117browse

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

How to delete nodes in javascript

The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.

In JavaScript, you can use the removeChild() or remove() method to delete nodes.

1. Use removeChild() to delete a node.

The removeChild() method deletes a specified child node of the specified element. Returns the deleted node as a Node object, or null if the node does not exist.

Syntax

node.removeChild(node)
  • node: required. The node object you wish to delete.

Example:








  • Coffee
  • Tea
  • Milk

单击按钮移除列表的第一项

Rendering:

How to delete nodes in javascript

[Recommended learning: js Basic Tutorial

2. Use the remove() method to delete nodes

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




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

Rendering:

How to delete nodes in javascript

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of How to delete nodes 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