Home>Article>Web Front-end> How to remove elements in html

How to remove elements in html

coldplay.xixi
coldplay.xixi Original
2021-04-28 11:51:40 6137browse

htmlMethods to remove elements: 1. Find the parent element of the deleted element, and delete the child elements that need to be deleted through the parent element; 2. Use JQuery to find and delete them directly.

How to remove elements in html

The operating environment of this tutorial: windows7 system, html5 version, DELL G3 computer.

htmlMethods to remove elements:

1. Use DOM objects

First you need to find the parent element of the deleted element, and use the parent element to The child elements that need to be deleted are deleted.

var el = document.getElementById('div2js'); el.parentNode.removeChild(el);

2. Use JQuery

to find and delete it directly.

$('#div2js').remove();

The above is the detailed content of How to remove elements in html. 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