標籤:query back 元素 htm utf-8 style 不同 min 另一個
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
var btn = $(this).text();
$("p").css("background-color","white");
$("p" + btn).css("background-color","yellow");
});
});
</script>
</head>
<body>
<button>:first</button>
<button>:first-child</button>
<button>:first-of-type</button><br><br>
<p>body 中第一個段落。</p>
<div style="border:1px solid;">
<p>div 中第一個段落,是 div 的第一個子項目。</p>
<p>div 中的最後一個段落,是 div 的最後一個子項目。</p>
</div><br>
<div style="border:1px solid;">
<span>這是一個 span 元素,是 div 中的第一個子項目。</span>
<p>另一個 div 中第一個段落,是 div 中的第二個子項目。</p>
<p>另一個 div 中的最後一個段落, 是 div 中的第三個子項目。</p>
<span>這是一個 span 元素,是 div 中的最後一個子項目。</span>
</div><br>
<div style="border:1px solid">
<p>另一個 div 中第一個段落,是 div 中的第一個子項目。</p>
<p>另一個 div 中的最後一個段落, 是 div 中的最後一個子項目。</p>
</div>
<p>body 中最後一個段落。</p>
</body>
</html>
jQuery中 :first、:first-child 和 :first-of-type 之間的不同