$("li:first-child").css("background-color", "green");
如上代码是获取 li为子元素,并且是第一个子元素的对象
<body>
<h3>改变每个"蔬菜水果"中第一行的背景色</h3>
<ol>
<li>芹菜</li>
<li>茄子</li>
<li>萝卜</li>
<li>大白菜</li>
<li>西红柿</li>
</ol>
<ol>
<li>橘子</li>
<li>香蕉</li>
<li>葡萄</li>
<li>苹果</li>
<li>西瓜</li>
</ol>
<ol>
<span>apple</span>
<li>橘子</li>
<li>香蕉</li>
<li>
<ul>
<li>apple</li>
</ul>
</li>
<li>葡萄</li>
<li>苹果</li>
<li>西瓜</li>
</ol>
<script type="text/javascript">
$("li:first-child").css("background-color", "green");
</script>