jQuery使用下面两个方法来删除或是清空某个HTML元素。
remove() – 删除指定的元素(包括其子元素)
empty() – 清空指定元素的子元素
<!DOCTYPE html>
<html>
<head>
<meta charset=
"utf-8"
>
<title>JQuery Demo</title>
<script src=
"scripts/jquery-1.9.1.js"
></script>
<script>
$(document).ready(
function
() {
$(
"button"
).click(
function
() {
$(
"#div1"
).remove();
});
});
</script>
</head>
<body>
<div id=
"div1"
style=
"height: 100px; width: 300px;
border: 1px solid black; background-color: yellow;"
>
This is some text
in
the div.
<p>This is a paragraph
in
the div.</p>
<p>This is another paragraph
in
the div.</p>
</div>
<br>
<button>Remove div element</button>
</body>
</html>
empty:
<!DOCTYPE html>
<html>
<head>
<meta charset=
"utf-8"
>
<title>JQuery Demo</title>
<script src=
"scripts/jquery-1.9.1.js"
></script>
<script>
$(document).ready(
function
() {
$(
"button"
).click(
function
() {
$(
"#div1"
).empty();
});
});
</script>
</head>
<body>
<div id=
"div1"
style=
"height: 100px; width: 300px;
border: 1px solid black; background-color: yellow;"
>
This is some text
in
the div.
<p>This is a paragraph
in
the div.</p>
<p>This is another paragraph
in
the div.</p>
</div>
<br>
<button>Empty the div element</button>
</body>
</html>
jQuery的remove()方法也支持一个参数,可以用于过滤一些需要删除的HTML元素。这个参数可以为任何有效的jQuery selector.
比如下面代码只删除class=”italic”的<p>元素:
|
$( "p" ).remove( ".italic" );
|
相关推荐
jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)...
jquery-1.11.1.js 、jquery-1.11.1.min.js 【官方jquery包 js】
jquery-3.5.0.js jquery-3.5.0.min.js.zip
jquery-3.1.1.js 、jquery-3.1.1.min.js 【jquery包 js】
这里包含jquery-ui-1.8.16.custom.min.js/jquery-ui-1.8.16.custom.css,我费了好长时间找到的,此东西可以配合jQuery UI开发指南一书使用。
jquery-3.0.0.js 、jquery-3.0.0.min.js 【官方jquery包 js】
jquery-ui-日期框扩展成时间框 jquery-ui时间框 基于别人的代码进行修改 jquery-ui-1.8.16.custom.css文件末尾加入以下代码 .ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; } .ui-timepicker-div dl{ ...
jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-...
jQuery版本迁移辅助插件,如果您使用的低版本jQuery改为高版本后出现错误,可以试试这个插件。用来检测和恢复在jQuery1.9版本中已删除或已过时的API。jquery-migrate-1.2.1.js,jquery-migrate-1.2.1.min.js
jquery-1.11.0 + jquery-UI-1.10.4
jquery-1.10.2.js 与 jquery-1.10.2.min.js , jquery的js包合集。
jquery-1.9.1.js 、jquery-1.9.1.min.js 【jquery包 js】
JQuery是一个快速简洁的JavaScript框架,jquery-3.3.1.js和jquery-3.3.1.min.js,需要的朋友可以下载。
jquery-1.3.2-vsdoc.js jquery-1.8.3.min.js jquery-1.3.2.min.js jquery-1.4.1-vsdoc.js jquery-1.4.1.min.js jquery-1.4.2-vsdoc.js jquery-1.4.2.min.js jquery-1.4.3-vsdoc.js jquery-1.4.3.min.js ...
jquery-ui-1.9.2.custom.min.js
jquery-1.12.4.min.js
值得注意的是:如果你正在使用jQuery Mobile,请使用最新的jQuery 1.7.2和jQuery Mobile 1.1这两个版本,因为之前的jQuery Mobile版本还基于jQuery core 1.7.1或更早的版本。 jquery-1.7.2.min.js (minified, ...
jquery-2.1.1.js 、jquery-2.1.1.min.js 【jquery包 js】
jquery-2.1.4.js 、jquery-2.1.4.min.js 【jquery包 js】
jquery-ui-1.7.3.custom 完整开发包