jQuery:选择没有特定后代元素的元素 [英] jQuery: Selecting elements that don't have a specific descendant element

查看:85
本文介绍了jQuery:选择没有特定后代元素的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用jQuery 1.3.2选择所有没有任何后代td元素的表元素?

How would I select all table elements that do not have any descendant td elements using jQuery 1.3.2?

推荐答案

您可以尝试:

$("table:not(:has(tbody > tr > td))").doStuff();

工作示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
  $("table:not(:has(tbody > tr > td))").css("background", "yellow");
});
</script>
<style type="text/css">
table { border-collapse: collapse; }
td, th { border: 1px solid black; }
</style>
</head>
<body>
<table>
<tr>
  <td>First table</td>
</tr>
</table>
<table>
<tr>
  <th>Second table</th>
</tr>
</table>
</body>
</html>

这篇关于jQuery:选择没有特定后代元素的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆