<!DOCTYPE html>
<html>
<head>
<title>index</title>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<style type="text/css">
</style>
</head>
<body>
<div id="n1" class="abc">
<div id="n2" class="abc">
<label id="n3">label1</label>
<span id="n4">span1</span>
<span id="n5" class="abc">span2</span>
<span id="n6">span3</span>
</div>
<div id="n7">
<span id="n8" class="abc">span1</span>
<span id="n9">span2</span>
</div>
</div>
</body>
</html>
<script>
$(function(){
$(".abc:first-of-type").css({
"border" : "2px solid red"
})
})
</script>
nth-of-type(n)
就上面的例子来说,被选中元素条件:相同type(相同类型标签)第n个且class是”abc”
·
nth-child(n)
$(“ul li:nth-child(2)”)
所有ul元素下第二个li元素