Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
Insert javascript method inside html paragraph
<!DOCTYPE html>
<html>
<body>

<h2>My First JavaScript</h2>

<p id="demo"><script>Date()</script></p>    <!-- here I want to put the output of Date() method -->

</body>
</html> 

I know that I can do something like:

<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>

But I'd like to know if there's a way to do that inside the paragraph directly.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use document.write to write content to the HTML directly from JavaScript.

<h2>My First JavaScript</h2>

<p id="demo"><script>document.write( Date())</script></p>

NOTE Calling document.write() after the initial HTML has been parsed will cause the entire HTML to be discarded and a new document will be created. This is only safe to be called while the document is being parsed.


Example of calling document.write after document has been processed

setTimeout(() => {
  document.write("Written after HTML doc was closed");
}, 5000);
<h1> Hello </h1>
<p> I will disappear after document.write is called</p>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda