html - Is it possible to use the :not() selector to target specific text nodes? -
this question has answer here:
- select text node css 6 answers
consider following html:
<div class="status-date"> <strong>date available:</strong> 10/05/2016 </div>
i'd expect :not()
selector capable of targeting date string "10/05/2016" follows:
.status-date *:not(strong) { text-decoration: underline; }
two questions:
1. :not()
selector capable of this?
2. if not, any css selector capable of this?
context: not styling text nodes. doing web scraping , i'd ignore <strong>
tag in case. if styling, target div
directly , overwrite styles on <strong>
"cancel out".
further context: can see naïve attempt doesn't work expected. example, shown in codepen: http://codepen.io/anon/pen/rwezqk it's possible i'm misunderstanding deep selector or dom structure i've described.
simple selectors represent elements. true simple selectors, including *
, :not()
. text contained element, not element in own right. won't able "match" text css selector, because far selectors concerned, dom calls text nodes don't exist in document tree.
the specification offers 3 lines on
:not()
selector.
the first line in specification supports this:
the negation pseudo-class, :not(x), functional notation taking simple selector (excluding negation pseudo-class itself) argument. represents element not represented argument.
notice says "it represents element".
if you're doing web scraping, consider xpath:
//div[contains(concat(' ', @class, ' '), ' status-date ')]/strong/following-sibling::text()
Comments
Post a Comment