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

删除html元素_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:36:33954browse

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

1.使用DOM对象

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

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

 

2.使用JQuery

直接找到并删除。

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

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