使用CSS选择文本节点 [英] Select text node with CSS

查看:129
本文介绍了使用CSS选择文本节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML标记:

 < h1> 
< div class =sponsor>
< span> Hello< / span>
< / div>
World
< / h1>

当我使用CSS选择器 h1 I get Hello World



有没有CSS选择器可以只接受文本节点?具体来说,世界在此示例中?



已编辑:
$ b

我不能改变标记,我只能使用CSS选择器,因为我使用的系统聚合rss feed。

解决方案

CSS的当前状态无法执行此操作,请检查此链接: W3C



这里的问题是您写入屏幕的内容不会显示在DOM:P中。



此外, :: outside 似乎还不起作用(至少对于我在Safari 6.0.3中)



检查我的小提琴,然后检查DOM来源: JSfiddle



最后有属性选择器 a {content:attr(href) ;} ,使CSS能够读取DOM节点属性。似乎没有一个 innerHTML 等同于这个。这将是巨大的,如果这是可能的,而你可以操纵标记的内部标记。


I have the following HTML markup:

<h1> 
     <div class="sponsor"> 
          <span>Hello</span>  
     </div> 
     World 
</h1>

When I use the CSS selector h1 I get Hello World.

Is there any CSS selector which I can take only the text node? Specifically the World in this example?

Edited:

I can't unfortunately change the markup and I have to use only CSS selectors because I work with the system that aggregates rss feeds.

解决方案

The current state of CSS can't do this, check this link: W3C

The problem here is that the content you write to the screen doesn't show up in the DOM :P.

Also ::outside doesn't seem to work yet (at least for me in Safari 6.0.3) or it simply doesn't generate the desired result yet.

Check my fiddle and then check the DOM source: JSfiddle

Finally there are attribute selectors a { content: attr(href);}, making CSS able to read DOM-node attributes. There doesn't seem to be a innerHTML equivalent of this yet. It would be great tho if that was possible, whereas you might be able to manipulate the inner markup of a tag.

这篇关于使用CSS选择文本节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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