/Anonimizzato31132Utente anonimizzato07 ago 2021, 10:05Premetto che non so usare javascript, ho provato a fare qualche prova random oggi. Html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="prova.css"> </head> <body> <button id="bottone">indietro</button> <div id="cont"></div> <script src="java.js"></script> </body> </html> CSS: body{display: flex; justify-content: center; align-items: center; margin: 0; padding: 0;} #cont{ border: 1px solid red; width: 1000px; height: 1000px; overflow: hidden; position: relative; } #cont.open{ height: 1500px; } #bottone{ cursor: pointer; padding: 20px; display: block; background-color: brown; } JavaScript: var button = document.getElementById("bottone"); var div = document.getElementById("cont"); button.onclick = function(){ if(div.className == "open"){ div.className == ""; } else{ div.className == "open" } } Vorrei capire perche non aumenta l'altezza del div quando clicco il bottone.
ninja72Utente AttivoIscritto damag, 2020Messaggi7907 ago 2021, 14:17Prova a modificare lo script in questo modo: const button = document.getElementById("bottone"); const div = document.getElementById("cont"); button.addEventListener('click', () => { div.classList.toggle('open') })