首页
极刻
圈子
教程
开源
登录 / 注册
返回教程: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(){ $("div:not(:has(h1))").css("background-color","yellow"); }); </script> </head> <body> <div> <h1>This is a heading (h1)</h1> <p>This is a paragraph.</p> </div> <div> <h2>This is a heading (h2)</h2> <p>This is a paragraph.</p> </div> <div> <h3>This is a heading (h3)</h3> <p>This is a paragraph.</p> </div> </body> </html>
运行结果