0

I found a javascript function that increments a value and then it's showed in a html div. It works perfectly in every browser except Firefox, and I'm really struggling to get a reason why.

The code looks like this:

<script type="text/javascript">

$(window).load(function(){
var amount = document.getElementById('amount');
var start = new Date("March 12, 2014 12:28:00").getTime();
var current;
update();

function update() {
    var current = (new Date().getTime() - start)/1000*1.00+0;
    amount.innerText = formatMoney(current);
}

setInterval(update,1000);

function formatMoney(amount) {
    var dollars = Math.floor(amount).toString().split('');
    var cents = (Math.round((amount%1)*100)/100).toString().split(',')[1];
    if(typeof cents == 'undefined'){
        cents = '00';
    }else if(cents.length == 1){
        cents = cents + '0';
    }
   var str = '';
    for(i=dollars.length-1; i>=0; i--){
        str += dollars.splice(0,1);
        if(i%3 == 0 && i != 0) str += '.';
    }
    return str + ' ' + '€';
}
});


</script>

<div id='amount'></div>
BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

2

Use amount.innerHTML instead.

See this post 'innerText' works in IE, but not in Firefox for the reason why amount.innerText does not work in Firefox.

Community
  • 1
  • 1
Kavka
  • 4,191
  • 16
  • 33
  • +1 Because of pointing the real problem, but since the accepted answer of the linked article is short, you could include it in your answer :) – Oriol Mar 26 '14 at 15:48
  • awesome guys! simple and accurate, great help. Thanks a lot. Keep up the great work. – user3464721 Apr 01 '14 at 11:14