DIV CSS 佈局教程網

用 jQuery 的 remove() 刪除指定 class 的元素
編輯:JQuery特效代碼     

本文示範如何使用 jQuery 的 remove() 方法,刪除符合指定條件的元素——這裡以 class 為例,移除帶有某 class 的段落。

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").remove(".italic");
  });
});
</script>
</head>
<body>
<p>This is a paragraph in the div.</p>
<p class="italic"><i>This is another paragraph in the div.</i></p>
<p class="italic"><i>This is another paragraph in the div.</i></p>
<button>Remove all p elements with class="italic"</button>
</body>
</html>

寫法 $("p").remove(".italic") 的意思是:在所有 <p> 元素中,只刪除那些帶有 italic class 的段落,其餘段落保留。希望本文對大家的 jQuery 開發有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved