How would I select all table elements that do not have any descendant td elements using jQuery 1.3.2?
+5
A:
You could try:
$("table:not(:has(tbody > tr > td))").doStuff();
Working example:
<!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>
cletus
2009-10-21 16:50:53
+1
A:
You're looking for the CSS :not()
selector.
table *:not(td)
Should do it.
Edit: bah, misread what you wanted.
Karl Guertin
2009-10-21 16:51:21
On the right track, but `table`s generally will *never* have immediate children that are `td`s, so this won't work as written.
Sixten Otto
2009-10-21 16:53:50
Yeah, ninja stealth edit. I think he's looking for the tables themselves rather than the tr/td/th I thought he was looking for.
Karl Guertin
2009-10-21 16:55:52
Yup, I was looking for the tables themselves.
Emzo
2009-10-21 17:28:53