案例:jQuery案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript" src="/js/jquery.js"></script>
4
<script type="text/javascript">
5
$(document).ready(function(){
6
  $("button").click(function(){
7
    $("p").offsetParent().css("background-color","red");
8
  });
9
});
10
</script>
11
</head>
12
<body>
13
<div style="width:70%;position:absolute;left:100px;top:100px">
14
<div style="margin:50px;background-color:yellow">
15
<p>点击下面的按钮可以设置本段落的最近的父(祖先)元素的背景色。</p>
16
<div>
17
</div>
18
<button>点击这里</button>
19
</body>
20
</html>
21