通过jQuery改变div:border right color

时间:2013-02-26 11:19:32

标签: jquery css ajax

如何将边框右侧颜色更改为类:

之后

这个css是正常的

.profile-options a div:after {
border-color: transparent #999999 transparent transparent;
border-style: solid;
border-width: 18px;
content: "";
display: block;
left: -15px;
margin-top: -33px;
position: absolute;
z-index: 999;}

当我被jquery

选中时,我需要将#999999设置为#333333

我尝试了那些,但似乎无法正常工作

$(".profile-options a div:after").css({"borderRightColor":"#999"});
$(".yourOptions1:after").css({"borderRightColor":"#333"});

2 个答案:

答案 0 :(得分:4)

您可以使用styleSheets

假设您有一个样式表,该规则是第一条规则,那么您需要做的就是:

document.styleSheets[0].cssRules[0].style.borderRightColor="#333333";

All you need to know about StyleSheets, Add, Remove, Alter, both IE and other Browsers

使用styleSheets还可以添加关于伪元素的css规则。

答案 1 :(得分:2)

您无法使用JQuery更改(:after)的样式。 但你可以通过在你使用的DIV之后在HTML中插入DIV来解决它 然后你可以使用JQuery

来处理它
<div class="mydiv_1"></div> <div class="after_div"></div>
<div class="mydiv_2"></div>  <div class="after_div"></div>