jumancy jumancy - 26 days ago 9
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
position:absolute;
top:0;
left:0;
}


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?

Answer

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.