Consider the following html:
<style>
.barcode { font-family: 'BC C39 3 to 1 Medium'; }
</style>
<div><span id='spn'>1234567</span></div>
The following will set the font to a barcode:
<script>
document.getElementById('spn').className = 'barcode';
</script>
But The following won't:
<script>
document.getElementById('spn').style.fontFamily = 'BC C39 3 to 1 Medium';
</script>
Why?
I need to use the style.fontFamily tag, not the className, but this appears to not be possible for some reason.
I know you already got your answer. But here some explanation why:
If you write
fontFamily = 'BC C39 3 to 1 Medium';then this equals writing:On MDN: Valid family names you have this paragraph:
So your font name - if written without quotes - is not valid due to the
3and1, if it is not surrounded by quotes. The same is true if you usestyle.fontFamilywhich is why it has to be:Or why
3and1would need to be escaped (but using quotes is the recommended way).