Javascript how to change font properties to script?

Tags: , ,



I found this script which is perfect for what I need. However I would like to change the font properties to make it bold and red for the result displayed. I looked all over and tried adding it but somehow I just seem to make it not function at all when I do. Any help is greatly appreciated. Here is my script.

<script type="text/javascript">
    var currentValue = 35;
    var add = function(valueToAdd){
        currentValue += valueToAdd;
        document.getElementById('number').innerHTML = currentValue;

    };
</script>

Answer

Use setAttribute to this element in DOM tree:

<script type="text/javascript">
    var currentValue = 35;
    var add = function(valueToAdd){
        currentValue += valueToAdd;
    var el = document.getElementById('number');
        el.innerHTML = currentValue;
        el.setAttribute('style', 'font-weight:bold; color:red;')
    };
</script>


Source: stackoverflow