sábado, 13 de mayo de 2023

JS - Mostrar y ocultar div con un botón

 Muestra el contenido del "Div" con un solo botón en Javascript..



Así de sencillo fue el código.


HTML
<button onclick="myFunction()">Ver</button>
<div id="myDIV">
  <img src="https://humanidades.com/wp-content/uploads/
2016/07/buho-1-e1560041723608-800x400.jpg" alt="">
</div> CSS DEPENDE COMO QUIERAS AJUSTAR EL BOTON


JS
function myFunction() {
    var x = document.getElementById("myDIV");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }
}

No hay comentarios:

Publicar un comentario