<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//libs.baidu.com/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>:nth-child(2)</button>
<button>:nth-last-child(2)</button>
<button>:nth-of-type(2)</button>
<button>:nth-last-of-type(2)</button>
<h1>body 中的标题</h1>
<p>body 中第一个段落。</p>
<p>body 中第二个段落。</p>
<div style="border:1px solid;">
<span>div 中的 span 元素</span>
<p>div 中的第一个段落。</p>
<p>div 中的第二个段落。</p>
<p>div 中的第三个段落。</p>
<p>div 中的第四个段落。</p>
<span>div 中的 span 元素</span>
</div><br>
<div style="border:1px solid;">