jQuery 文檔操做 - remove() 方法

移除全部 <p> 元素:

定義和用法

remove() 方法移除被選元素,包括全部文本和子節點。javascript

該方法不會把匹配的元素從 jQuery 對象中刪除,於是能夠在未來再使用這些匹配的元素。php

但除了這個元素自己得以保留以外,remove() 不會保留元素的 jQuery 數據。其餘的好比綁定的事件、附加的數據等都會被移除。這一點與 detach() 不一樣。html

語法

$(selector).remove()
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("p").remove();
  });
});
</script>
</head>
<body>
<p>這是一個段落。</p>
<p>這是另外一個段落。</p>
<button>刪除全部 p 元素</button>
</body>
</html>
相關文章
相關標籤/搜索