Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
DOM input .value returns null using getElementById in function

index.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>

main.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);
}

Paste a link into the input element and then click the button. The following is printed to the console.

link is null

If I instead console.log the return of 'document.getElementById("LinkInput")', this is returned:

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

Browser-Sync version 2.27.7 is being used to serve the files. The CLI command used was:

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

Question

Based on this w3schools js example, .value should return the value typed into the <input> instead of null. Why does it not?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem originates with browser-sync, not the code or the browser.

Run

npm update browser-sync

and then try again.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda