Home  >  Article  >  Web Front-end  >  jquery delete and clear elements

jquery delete and clear elements

无忌哥哥
无忌哥哥Original
2018-06-29 14:43:361572browse

jquery delete and empty elements

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>删除与清空元素</title>
<style type="text/css">
li {width: 300px;}
.hot {background-color: lightgreen;}
.top {background-color: yellow;}
</style>
</head>
<body>
<ul>
<li><a href="">php中文网2018年最新教学视频01</a></li>
<li><a href="">php中文网2018年最新教学视频02</a></li>
<li><a href="">php中文网2018年最新教学视频03</a></li>
<li><a href="">php中文网2018年最新教学视频04</a></li>
<li><a href="">php中文网2018年最新教学视频05</a></li>
<li><a href="">php中文网2018年最新教学视频06</a></li>
<li><a href="">php中文网2018年最新教学视频07</a></li>
<li><a href="">php中文网2018年最新教学视频08</a></li>
<li><a href="">php中文网2018年最新教学视频09</a></li>
<li><a href="">php中文网2018年最新教学视频10</a></li>
</ul>
<button>remove()删除绿色背景元素</button>
<button>empty()清空黄色背景元素的内容</button>
</body>
</html>

* 1. remove(): delete element

* Parameters: selector

$(&#39;button&#39;).eq(0).on(&#39;click&#39;,function(){
//实例: 删除列表中类样式为hot的元素,条件由filter()给出
$(&#39;li&#39;).filter(&#39;.hot&#39;).remove()
//也可以将删除条件写到remove()方法参数中,这样可简化语句
$(&#39;li&#39;).remove(&#39;.hot&#39;)
})

* 2. empty()

* Parameters: None

* Function: Clear the content of the element, most used when calling Ajax

$(&#39;button:first&#39;).next().click(function () {
$(&#39;li&#39;).filter(&#39;.top&#39;).empty()
})

The above is the detailed content of jquery delete and clear elements. 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
Previous article:jquery element wrappingNext article:jquery element wrapping