Answer the question
In order to leave comments, you need to log in
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";
};
Answer the question
In order to leave comments, you need to log in
jsfiddle.net/66q7u39h/2
But it doesn't work, because not innerText , but textContent .
Well, the code is very redundant.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question