Prior to writing this answer, I didn't realise that editing Pseudo Elements (::after
) with JavaScript was a little trickier. Although with this question/answer on StackOverflow made it relatively easy with JavaScript.
The concept was still the same, upon Page load the browser renders what is stated on the Style sheet, there after you must use JavaScript to manipulate it's contents to render something different.
Hence the CSS looks at the attr(data-content)
, which means it'll look for the data-content
attribute within the HTML.
.bs-docs-example::after {
content: attr(data-content);
}
This looks for the data-content=""
:
<div class="bs-docs-example" data-content="Example Header">
Which renders:

To change it there after, all you have to do is change it's data-content
attribute with JavaScript, in the demo I use jQuery to quickly select the DOM element and adjust it's data-content
attribute.
$('.bs-docs-example').attr('data-content', "New Header Title" );
Demo Fiddle: http://jsfiddle.net/u2D4M/
If you wanted to do this without jQuery:
<script>
var getHeader = document.getElementById('bs-header');
getHeader.attributes["data-content"].value = "Hi, New Title";
</script>
Demo Fiddle: http://jsfiddle.net/9wxwxd4s/