Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
Cómo pasar datos de Node.js a html

Tengo un programa simple y algunas cadenas de datos que quiero pasar a la página HTML alojada localmente, pero recibo el error: Error de referencia: el documento no está definido

Ahí está mi archivo .js index.js:

 let some_string = "some data"; document.getElementById("dataButton").onclick = function(){ var paragraph = document.createElement("p"); var text = document.createTextNode(some_string); paragraph.appendChild(text); var element = document.getElementsByTagName("body")[0]; element.appendChild(paragraph); }

Y ahí está mi HTML test.html:

 <!DOCTYPE html> <html> <head> <title>New title</title> </head> <body> <h1>Data page</h1> <button id="dataButton">Add data</button> <script src="index.js"></script> </body> </html>

¡Muchas gracias si a alguien se le ocurre una idea de qué estoy haciendo mal!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Actualice sus archivos a lo siguiente

 let some_string = "some data"; const dataButton = document.getElementById("dataButton"); dataButton.addEventListener("click", () => { var paragraph = document.createElement("p"); var text = document.createTextNode(some_string); paragraph.appendChild(text); var element = document.getElementsByTagName("body")[0]; element.appendChild(paragraph); });
 <!DOCTYPE html> <html> <head> <title>New title</title> </head> <body> <h1>Data page</h1> <button id="dataButton">Add data</button> <script src="./index.js"></script> </body> </html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!