There is a much simpler way: just set the value of the content property of the pseudo-element content to attr(some-attribute-name) , it will use the value of the HTML attribute for the parent as the content of the pseudo-element. Then you can use the setAttribute() method on the parent to dynamically change the value. Below are mock fragments of how this method will look in action. I also made a blog post with more details , which contains a live sample script.
CSS
#SomeElement:after { content: attr(some-attribute-name); }
HTML
<div id="SomeElement" some-attribute-name="Pseudo content here!"></div>
JavaScript (for changing pseudo content)
var someElement = document.getElementById('SomeElement'); someElement.setAttribute('some-attribute-name', 'New pseudo content here!');
csuwldcat Aug 09 '12 at 19:57 2012-08-09 19:57
source share