2

我想改变边框底部的颜色.arrow_box:after

JavaScript

document.getElementsByClassName("arrow_box:after")[0].style.borderBottomColor="blue";

但它不起作用!

这是小提琴上的相同示例

4

1 回答 1

2

您不能:after直接通过 JS 更改伪元素的样式(也可以选择它们)。原因是它们不是 DOM 树的一部分。

您可以做的最好的事情是为元素分配另一个类,如下所示:

document.getElementsByClassName("arrow_box")[0].className = "arrow_box blue-border";

.arrow_box.blue-border:after {
    border-bottom-color: blue;
}
于 2013-02-17T08:11:10.227 回答