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

107
Visualizações
Searching and referencing html files in js file

So I was doing some grasshopper HTML learning and thought that I could replicate it...

Oh how naive, I was...

The intention was to change text in a button when clicked

Here is the reference JS code

let button1 = document.getElementById('button1');
button1.addEventListener('click', () => {
    button1.textContent = 'Clicked!';
});

and html reference

<html>
    <body>
        <button id='button1'>Fresh Button1</button>
    </body>
</html>

Unfortunately, however much I tried to make it work, I kept getting told off by VS Code that

Uncaught ReferenceError ReferenceError: document is not defined

I don't know how to fix it, I've tried everything, scripting it IN the HTML file, making a variable that would pull it from the html file,... (sub-question: is it possible to reference a document in JS, like the src="" in HTML?)

I've spent the better part of my evening grinding on this and want to throw my pc out of the window. I don't know if it's just a syntax error or if I'm using it wrong... I just don't know.

Please help, thanks

Sincerely, Seven

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

I've spent the better part of my evening grinding on this and want to throw my pc out of the window. I don't know if it's just a syntax error or if I'm using it wrong... I just don't know.

Don't throw your pc out the window. There's no syntax error. You've done everything right.

I don't know how to fix it

Trust me, there's nothing to fix.

Here is your code below.

It works:

let button1 = document.getElementById('button1');

button1.addEventListener('click', () => {
    
    button1.textContent = 'Clicked!';
});
<button type="button" id="button1">Fresh Button1</button>

about 4 years ago · Santiago Gelvez Relatório

0

[edit] Deleted my wrong answer - sorry!

about 4 years ago · Santiago Gelvez 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