It's impossible to manipulate the pseudo-selector :after
directly through JavaScript, because it doesn't technically exist in the DOM. There are workarounds depending on specific use case, though unfortunately these workarounds only allow you to manipulate the content (not the styling) of pseudo-selectors.
As such, you simply cannot change the colour of a border in :after
, and your only option is to make use of the element directly.
If you weren't making use of :after
, and were instead targeting the element directly, you'd be looking for .style.borderBottom
:
var target = document.getElementsByClassName('canChoose')[0];
target.style.borderBottom = "8px solid red";
.canChoose {
width: 20px;
margin-top: 5px;
margin-left: auto;
margin-right: auto;
border-bottom: 8px solid #5A8C19;
border-radius: 10px;
content: "";
display: block;
}
<div class="canChoose"></div>
Note that there's no JavaScript method to access the colour directly. Instead, you have to type out the full border declaration as you would for CSS (like 8px solid red
).
Hope this helps! :)