Home > Web Front-end > HTML Tutorial > 删除html元素_html/css_WEB-ITnose

删除html元素_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:36:33
Original
1021 people have browsed it

如果需要将id是‘div2js’的div元素删除。

1.使用DOM对象

首先需要找到被删元素的父元素,通过父元素将其需要删除的子元素删除。

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

 

2.使用JQuery

直接找到并删除。

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template