Monday, 11 December 2017

css selectors - What is the alternative to CSS-selecting an ancestor

itemprop="text">


CSS(3) has descendent
selectors, e.g. td em {color: red};, but href="https://stackoverflow.com/questions/1251768/css-parent-ancestor-selector">no
ancestor selector, apparently.



So,
what should I do instead of something like td {border: 1pt solid red}
em;
? i.e., how can I set a style on ancestors of some (X)HTML
element?



Note:




  • Javascript is not
    relevant for the workaround, something XPath'y might
    be.


itemprop="text">
class="normal">Answer





You can wait for CSS4 selectors to
be implemented, then do



td! em
{
border: 1pt solid
red;
}


See
rel="nofollow">http://dev.w3.org/csswg/selectors4/.



Or...




var
xpathresult = document.evaluate("//td[.//em]",
document, null,
XPathResult.ANY_TYPE, null);
while (e=xpathresult.iterateNext()){

e.classList.add("border");
}


See
rel="nofollow">https://developer.mozilla.org/en-US/docs/DOM/document.evaluate.
Normal browser support caveats apply.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...