Jquery教程
Jquery动效
Jquery HTML/CSS
Jquery 事件
jquery常用

jQuery remove()

jQuery remove()方法用于从DOM中删除所选元素。它将删除所选元素本身以及其中的所有内容(包括所有文本和子节点)。此方法还删除所选元素的数据和事件。
注意:如果要删除元素而不删除数据和事件,则应使用detach()方法。如果只想删除数据和事件,请使用empty()方法。
语法:
$(selector).remove(selector)

jQuery remove()方法的参数:

参数 说明
selector 是可选参数。它指定是否删除一个或多个元素。如果必须删除多个元素,则应使用逗号(,)分隔它们。

jQuery remove()方法的示例

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>remove demo</title>
  <style>
  p {
    background: pink;
    margin: 6px 0;
  }
  </style>
  <script src="/jquery-1.10.2.js"></script>
</head>
<body>
 <p>Hello Guys!</p>
This is lidihuo.com<br/>
<p>A place for all technology.</p>
<button>Execute remove() method on paragraphs</button>
 <script>
$("button").click(function() {
  $("p").remove();
});
</script>
</body>
</html>
输出:

Hello Guys!

This is lidihuo.com

A place for all technology.

jQuery remove()示例2

<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").remove();
    });
});
</script>
</head>
<body>
<p>Welcome Guys!</p>
<p><b>This is lidihuo.com</b></p>
<button>Click here to execute remove() method</button>
</body>
</html>
输出:

Welcome Guys!

This is lidihuo.com

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4