Div is not showing up

Asked

Viewed 27 times

0

I’m trying to make a div appear right after the other, but when I put the function, only the first one disappears and the second one doesn’t appear.

<script>
    function apareceDiv1(){
 document.getElementById("est").style.display="block";

}
   function mostraHoras(){
    var hora = new Date();

    document.getElementById("segundos").innerHTML = hora.getSeconds();
}
    function apareceDiv2(){
 document.getElementById("est2").style.display="block";
}
    function fechaDiv1(){
        document.getElementById("est").style.display="none";
    }
    function apareceDiv3(){
 document.getElementById("est3").style.display="block";
}
    window.onload = function(){
        var cronometro = document.getElementById("cro");
        var fot = document.getElementById("fotos");
        var tabuada = document.getElementById("tab");

        setInterval(mostraHoras,1000);
        cronometro.onclick = apareceDiv1; mostraHoras;

        fot.onclick = fechaDiv1; apareceDiv2; 
        tabuada.onclick = apareceDiv3;


    }

    </script>
</head>

1 answer

0

Simple, in onclick you are adding 2 values erroneously so fot.onclick = closeDiv1; appeared Iv2; this does not work, create an onclick function looks much better, it will be waiting to receive click, when receive performs the desired functions, The way you were doing would only run the first one because you closed with a ";" and look there if that’s all yet. Any doubt just talk

thus

<script>
    function apareceDiv1(){
 document.getElementById("est").style.display="block";

}
   function mostraHoras(){
    var hora = new Date();

    document.getElementById("segundos").innerHTML = hora.getSeconds();
}
    function apareceDiv2(){
 document.getElementById("est2").style.display="block";
}
    function fechaDiv1(){
        document.getElementById("est").style.display="none";
    }
    function apareceDiv3(){
 document.getElementById("est3").style.display="block";
}
    window.onload = function(){
        var cronometro = document.getElementById("cro");
        var fot = document.getElementById("fotos");
        var tabuada = document.getElementById("tab");

        setInterval(mostraHoras,1000);

 cronometro.addListener('click', function() {
   apareceDiv1();
   mostraHoras();
});

fot.addListener('click', function() {
  fechaDiv1();
  apareceDiv2();
});

  tabuada.addListener('click', function() {
    apareceDiv3();
});

    }

    </script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.