Estoy haciendo una página .html de broma para un amigo. La broma era que presionabas un botón y aparecía una frase debajo del botón. Descubrí una manera de ocultar la frase y mostrarla. El problema es que, cuando carga en la página, la frase ya estaría en la pantalla. ¿Cómo lo mantengo oculto al cargar la página?
function Function() { var x = document.getElementById("urmom"); if (x.style.display === "none") { x.style.display = "block"; } else { x.style.display = "none"; } } <p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p> <button onclick="Function()">Try it</button> <div id="urmom"> ur mom </div> <p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>Establecer con CSS primero como NINGUNO.
function Function() { var x = document.getElementById("urmom"); if (x.style.display === "none") { x.style.display = "block"; } else { x.style.display = "none"; } } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p> <button onclick="Function()">Try it</button> <div id="urmom" style="display:none"> ur mom </div> <p><b>Note:</b> The element will not take up any space when the display property set to "none".</p> </body> </html>