JavaScript: get the computed style of the CSS content property

by J. Albert Bowden

HTML

<div id="test">Test content</div>
<p id="output"></p>

CSS

#test {
    margin: 1em;
}

#test:before {
    content: 'Before ';
}

#output {
    font-family: monospace;
    margin: 1em;
}

JavaScript

var test = document.querySelector('#test');
var result   = getComputedStyle(test, ':before').content;
var output = document.querySelector('#output');
output.innerHTML = result;