首页
极刻
圈子
教程
开源
登录 / 注册
返回教程:jQuery 教程
TRY RUN / 在线示例
jQuery 教程 尝试一下
jQuery 教程 尝试一下
源代码
运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>安科教程(www.ancii.com)</title> <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p").click(function(){ if ($("p").parent().is("div")) { alert("p 的父元素是 div"); } }); }); </script> </head> <body> <div> <p>点我查看父元素是否是 div。</p> </div> </body> </html>
运行结果