2

I am familiar with the :empty selector to select an element that contains no tags and also no text, but that's a step too far for me. I would like to know if there is a way to select tags that contain no child tags, but may contain some text.

For my purposes, it is acceptable to use CSS which only works on the latest version of Google Chrome (since this is intended for a Chrome extension).

4

1 回答 1

3

您可以通过 CSS 实现此目的的唯一方法是使用:not 选择器排除可能适合作为该特定父项的子项的每个标记。

但是,使用 JQuery,您可以使用以下代码(例如)来做到这一点:

if ( $('#myParent').children().length == 0 ) {
     // do something
}
于 2013-08-30T02:28:19.960 回答