DIV CSS 佈局教程網

用 jQuery 的 hide() 隱藏指定 id 的元素
編輯:JQuery特效代碼     

本文示範如何使用 jQuery 的 hide() 方法,隱藏 id 為 test 的元素。

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#test").hide();
  });
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p id="test">This is another paragraph.cnblogs.com</p>
<button>Click me</button>
</body>
</html>

以 id 選擇器 $("#test") 精準選到單一元素並將其隱藏。由於 id 在頁面中理應唯一,因此這種方式很適合用來操作特定的某個元素。希望本文對大家的 jQuery 開發有所幫助。

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