首页
极刻
圈子
教程
开源
登录 / 注册
返回教程:jQuery 教程
TRY RUN / 在线示例
jQuery 教程 尝试一下
jQuery 教程 尝试一下
源代码
运行
<!DOCTYPE html> <html> <head> <script src="//libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").offsetParent().css("background-color","red"); }); }); </script> </head> <body> <button>Set background-color</button> <div style="border:1px solid black;width:70%;position:absolute;left:10px;top:50px"> <div style="border:1px solid black;margin:50px;background-color:yellow"> <p>Click button to set the background color of the first positioned parent element of this paragraph.</p> </div></div> </body> </html>
运行结果