Chicos, estoy intentando algo para mi carpeta, pero estoy atascado y mi cerebro no puede entender lo que se supone que debo hacer, ¿pueden ayudarme, por favor?
Así que tengo una sección div que estoy ocultando, luego, con un BOTÓN (Más), se supone que debe mostrar el div, y el BOTÓN (Más) debería cambiar a BOTÓN (MENOS). Y realmente quiero que funcione de la forma en que lo estoy haciendo porque sé que puede funcionar, pero no estoy muy seguro de cómo hacerlo. ingrese la descripción de la imagen aquí
Puede usar HTMLelement.addEventListener para manejar el evento de clic de botón y ocultar o mostrar el div apropiadamente usando la propiedad element.style.display , el siguiente código demuestra cómo funciona
const divE = document.getElementById('more'); const btn = document.getElementById('show'); handler = () => { if (divE.style.display != 'none') { // if the element is not hidden, hide the element and change button text to "more" btn.innerHTML = 'More'; divE.style.display = 'none'; } else { // if the element is hidden, show the element and change button text to "less" btn.innerHTML = 'Less'; divE.style.display = 'block' } } btn.addEventListener('click', handler) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <button id="show">Less</button> <div id="more"> IDk something here ig </div> </body> </html>