利用ruleSelector("ref::before")[0].style
の代わりdocument.getOverrideStyle(ref, ':before')
にいくつかのID /クラス名の魔法を行う必要があります。
http://jsfiddle.net/s3fv8e5v/4/
<!DOCTYPE html>
<title>CSS</title>
<style>
body {
font: 200%/1.45 charter;
}
ref::before {
content: '\00A7';
letter-spacing: .1em;
}
</style>
<article>The seller can, under Business Law <ref>1782</ref>, offer a full refund to buyers. </article>
<script>
function ruleSelector(selector) {
function uni(selector) {
return selector.replace(/::/g, ':') // for Firefox
}
return Array.prototype.filter.call(Array.prototype.concat.apply([], Array.prototype.map.call(document.styleSheets, function(x) {
return Array.prototype.slice.call(x.cssRules);
})), function(x) {
return uni(x.selectorText) === uni(selector);
});
}
var toggle = false,
pseudo = ruleSelector("ref::before").slice(-1);
document.querySelector("article").onclick = function() {
pseudo.forEach(function(rule) {
if (toggle = !toggle)
rule.style.color = "red";
else
rule.style.color = "black";
});
}
</script>
も良く、http://stackoverflow.com/questions/5041494/manipulating-css-before-and-after-pseudo-elements-using-jquery – benesch
@primatology見ますBoltClockがそこでそれに答えたようです:http://stackoverflow.com/a/5041526/107152しかし、Chromeには、それらにアクセスするための特別な方法がありますか? – Qtax
[JavaScriptからCSS擬似クラスルールを設定する]の複製が可能です。(http://stackoverflow.com/questions/311052/setting-css-pseudo-class-rules-from-javascript) – user123444555621