jQuery中 :first、:first-child 和 :first-of-type 之間的不同

來源:互聯網
上載者:User

標籤: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 之間的不同

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.