admin管理员组文章数量:1315982
Is there any way to select only innermost tables? That is ones that do not contain any more tables inside them?
I know I can filter by element.getElementsByTagName("table").length == 0
, I'm just wondering if there's a more elegant solution.
Is there any way to select only innermost tables? That is ones that do not contain any more tables inside them?
I know I can filter by element.getElementsByTagName("table").length == 0
, I'm just wondering if there's a more elegant solution.
4 Answers
Reset to default 12With pure CSS you can't do this. With jQuery (which your question is tagged with) you can:
$("table:not(:has(table))")...
will select tables with no child tables.
The :has()
selector finds elements elements that have a particular descendant. :not()
inverts the selection to those that don't have that particular descendant.
For those using CSS selectors in nokogiri, :has()
may be broken, so :not(:has(...))
won't work. You'll want to use xpath
or some other way. See :has CSS pseudo class in Nokogiri.
As far as I know there is no CSS selector that fits your need. However, there are several options:
- Use a class or an id to mark the table so that you can select it.
- Use javascript to navigate the DOM treee.
- Use a javascript library to select the elements. As you tagged your OP with the jQuery tag I'd suggest that you go for that.
Do you have a chance to add a class="innermost"
attribute to the table? That way, it's just moch simpler.
本文标签: javascriptCSS selector for innermost TABLEsStack Overflow
版权声明:本文标题:javascript - CSS selector for innermost TABLEs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741975224a2408079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论