Home>Article>Web Front-end> How to get elements and delete them in javascript

How to get elements and delete them in javascript

青灯夜游
青灯夜游 Original
2021-06-22 12:50:40 2851browse

Javascript method to get and delete elements: First use the "document.querySelector(element name)" or "document.getElementById(id value)" statement to get the element object; then use "element object.remove()" Statement to delete elements.

How to get elements and delete them in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript method to get and delete elements

    
div元素

Rendering:

How to get elements and delete them in javascriptDescription:

# The ##querySelector() method returns an element in the document that matches the specified CSS selector.

The getElementById() method returns a reference to the first object with the specified ID.

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

[Related recommendations:

javascript learning tutorial]

The above is the detailed content of How to get elements and delete them 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