jumancy jumancy - 7 months ago 55
Javascript Question

How change content value of pseudo :before element by Javascript

I have the grap constructured by CSS, which is dynamically changes by JS. I show graph max value by pseudo element as:

.graph:before {
content:""; //value that want set by JS

That's why I need to set this value by JS. I tried
$(".graph:before").css("content", hh);
but it didn't help. How to get that value?


You can't modify pseudo elements through JavaScript since they are not part of the DOM. Your best bet is to define another class in your CSS with the styles you require and then add that to the element. Since that doesn't seem to be possible from your question, perhaps you need to look at using a real DOM element instead of a pseudo one.