A
A
Alexander Lashchevsky2014-08-27 00:03:20
Mozilla
Alexander Lashchevsky, 2014-08-27 00:03:20

Why doesn't the script work in Firefox?

Hello!
There are 5 blocks, they are all display: none. There is one more block, depending on the content of which one of the five is shown. If the content of the block is the number "1", the block with id1 is shown, and so on.

div {display: none;}

<div id="idNumber">1</div>
<div id="id1">Блок №1</div>
<div id="id2">Блок №2</div>
<div id="id3">Блок №3</div>
<div id="id4">Блок №4</div>
<div id="id5">Блок №5</div>

var idNumber = document.getElementById('idNumber').innerText;
if (idNumber == 1) {
  obj=document.getElementById("id1"); 
  obj.style.display="block";}
;
if (idNumber == 2) {
  obj=document.getElementById("id2"); 
  obj.style.display="block";
};
if (idNumber == 3) {
  obj=document.getElementById("id3"); 
  obj.style.display="block";
};
if (idNumber == 4) {
  obj=document.getElementById("id4"); 
  obj.style.display="block";
};
if (idNumber == 5) {
  obj=document.getElementById("id5"); 
  obj.style.display="block";
};

Same for JSFiddle .

Everything works well in all browsers, but it does not want to in Fox.
I thought about rewriting it to jQuery, and this might even solve the problem, but the interest remains in any case: what could be the problem? How to make it work in Fox?

Sincerely,
Alexander.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petrov, 2014-08-27
@Alexanevsky

jsfiddle.net/66q7u39h/2
But it doesn't work, because not innerText , but textContent .
Well, the code is very redundant.

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question