How to change :: after and :: before of an element with Javascript?


I need to change the content attribute of the after and before pseudo elements of the next HTML element without using libraries like jQuery . If I did something similar with CSS it would be something like this:


What would be the way to do it with Javascript?

var text = document.getElementById("text");


You can prepare :: after and :: before to load the content of an attribute by default.

In the example I have used the "title" attribute:

  content: attr(title);

And then update it with Javascript.

document.querySelector("#text").setAttribute("title" , "Nuevo texto")


document.querySelector("#text").title = "Nuevo texto";
Scroll to Top