2012-10-11 33 views
3

如果div的innerHtml匹配正則表達式,我想將css應用於我的div標籤。我無法找到正確的搜索條件谷歌它。如果已經在SO上詢問過,請告訴我。如何將css應用於基於正則表達式的div內容

//CSS: 

#main div[/* regex here which matches Foo. It will make the div red */] { 
    color: red; 
} 

//HTML: 
<div id="main"> 
    <div>This text contains Foo. It contains other stuff too</div> 
    <div>Red color will not be applied to this div because regex doesn't match</div> 
</div> 

我看到匹配使用正則表達式的屬性其實例。例如this。我只是無法找到正確的'正則表達式'來匹配div的內容。我不想使用Javascript並解析文本。 PS:我不必在IE,Safari,Opera上有這個東西,所以Chrome/Mozilla特有的任何東西也會有所幫助。

謝謝。

回答