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

168
Views
La entrada DOM .value devuelve nulo usando getElementById en la función

índice.html

 <!DOCTYPE html> <html> <head> <script src="main.js"></script> </head> <body> <div> <input id="LinkInput" type="text"> <button id="Add">Add Link</button> </div> </body> </html>

principal.js

 document.addEventListener("DOMContentLoaded", (event) => { document.getElementById("Add").addEventListener("click", addLink); }); var addLink = function () { let link = document.getElementById("LinkInput").value; console.log("link is " + link); }

Pegue un enlace en el elemento de entrada y luego haga clic en el botón. Lo siguiente se imprime en la consola.

 link is null

Si, en cambio, console.log el retorno de 'document.getElementById("LinkInput")', esto se devuelve:

 <input id="LinkInput" type="text">

Se está utilizando Browser-Sync versión 2.27.7 para servir los archivos. El comando CLI utilizado fue:

 browser-sync start --server --directory --files "*/**"

Pregunta

Según este ejemplo de w3schools js , .value debería devolver el valor escrito en <input> en lugar de nulo. ¿Por qué no?

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

0

El problema se origina con la sincronización del navegador, no con el código o el navegador.

Correr

 npm update browser-sync

y luego inténtalo de nuevo.

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!