Cómo mostrar un oculto html etiqueta <p> elemento con JavaScript?

0

Pregunta

Tengo el siguiente ocultos <p> elemento en el cuerpo de la etiqueta de mi archivo HTML (para mi extensión de chrome).

<p hidden id="button">
    <a id="dashboard-btn" href="www.google.com" target="_blank" rel="noopener noreferrer">
      www.google.com
    </a>
</p>

Quiero mostrar este usando JavaScript. Mi aleatoria intentar que no se pudo mostrar:

document.getElementById("button").style.visibility = 'visible';

[RESUELTO] Esto (también) trabajó:

document.getElementById("button").style.display = "block";
5
3

Usted puede utilizar removeAttribute

document.getElementById("button").removeAttribute('hidden')
<p hidden id="button">
  <a id="dashboard-btn" 
     href="www.google.com" 
     target="_blank" 
     rel="noopener noreferrer">
      www.google.com
    </a>
</p>

2021-11-11 14:44:30

Además, esto también trabajó: document.getElementById("button").style.display = "block";
stacvolken
3

Ocultar su elemento con el atributo hidden así que hay que controlar ese atributo en lugar de estilo como:

document.getElementById("button").hidden = false; 
<p hidden id="button">
    <a id="dashboard-btn" href="www.google.com" target="_blank" rel="noopener noreferrer">
      www.google.com
    </a>
</p>

Referencia:

2021-11-11 14:44:33
1

Probar con este

document.getElementById("button").removeAttribute("hidden")
2021-11-11 14:45:05
1

Usted puede quitar el atributo de "oculto".

document.getElementById("button").removeAttribute("hidden")

2021-11-11 14:45:48
0

Tengo varias soluciones:

Un

document.getElementById("button").hidden = "false";

Como oculto no es un css visibility : hidden; la propiedad.

Es un atributo.

B

Como @tacoshi mencionado,

.hidden {
  opacity: 0;
  transition: opaicty 1s ease;
  /* use opacity in case you want to have a beautiful transition */
}

Y sólo tiene que utilizar

document.getElementById("button").classList.toggle("hidden")
2021-11-11 14:50:35

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................