0

I have one line of javascript code that firefox only wont run. I have searched through stackoverflow, mozilla etc...all point to javascript being enabled but it is enabled and all script except one line wont run. It is within an if statement - one statement executes in the 'if' statement and the other doesnt. No answers anywhere on topic

this is my code:

/*figuring out how to fill in cell values using js*/

//need to set i counter according to which day is the 1st of the month

var i; //loop counter - correlates to <td> array

switch(firstId) {
    case 1 :
        i = 0;
        break;
    case 2 :
        i = 1;
        break;
    case 3 :
        i = 2;
        break;
    case 4 :
        i = 3;
        break;
    case 5 :
        i = 4;
        break;
    case 6 :
        i = 5;
        break;
    case 7 :
        i = 6;
        break;
}

var add = i;
var subt = i - 1;
var x = document.getElementsByClassName("jan");
for(i; i < count + add; i++) {
    x[i].style.backgroundColor = "#dadfe7";
    x[i].innerText = (i - subt);
}

Firefox wont run this line x[i].innerText = (i - subt); the last line in the if statement but Chrome and Safari do. No errors are thrown that I can see in chrome or firefox inspectors.

I would greatly appreciate any help. You can see the results by going to http://sunsetprayers.com/

It is a 2016 Calendar - I am learning javascript and want to have the months load in the correct squares using javascript code.

Any help is greatly appreciated!! ~jeanie

depperm
  • 10,606
  • 4
  • 43
  • 67
jeaniem
  • 3
  • 1
  • Possible duplicate of ['innerText' works in IE, but not in Firefox](http://stackoverflow.com/questions/1359469/innertext-works-in-ie-but-not-in-firefox) – rosscj2533 Jan 13 '16 at 16:27
  • Why would you use that switch statement instead of just a single `if` statement that subtracts 1 from `firstId` and assigns it to `i`? – jfriend00 Jan 13 '16 at 16:32

1 Answers1

3

innerText is an invention of Internet Explorer, that maybe Chrome adapts to it. But is not an standard. To write the standard use textContent:

https://developer.mozilla.org/en/docs/Web/API/Node/textContent

x[i].textContent = (i - subt);

In the documentation you can find the differences between textContent and innerText and innerHTML

Note that you said:

I have searched through stackoverflow, mozilla etc...all point to javascript being enabled but it is enabled and all script except one line wont run.

But that's not true, I spent 10 seconds to find the MDN documentation about that.

Marcos Pérez Gude
  • 21,869
  • 4
  • 38
  • 69
  • 1
    Thank you, Marcos!! That fixed it. And I am going to read that entire documentation you found in 10 seconds!!! I wish I had found that. Being pretty new to javascript I am not 100% the right terms to find the answers I need. But I will 100% read all of this you shared. Super grateful for your time!!! – jeaniem Jan 13 '16 at 22:43
  • You're welcome, don't worry. Make a good search saves you a lot of time!! Good luck :) – Marcos Pérez Gude Jan 14 '16 at 08:33
  • Thank you!! and to you too.. in all you do :-) – jeaniem Jan 14 '16 at 21:46