0

Im learning JS. Found a good video "JavaScript Programming - Full Course" and stucked at the 2nd part where I need to use DOM. I have the HTML document, in i refered to the JS file. Other stuff working well, but this:

let messageEL = document.getElementById("message-el")

Always get this error:

ReferenceError: document is not defined

I installed live server, and it works one time, than stops.

What can I do, to fix this? Do I need to download some extension? Please tell me the solution as simple as u can Im at the beginning of the learning path.

This is the code and the error

MDavid
  • 23
  • 1
  • 2
  • node is to run JS only documents, outside a browser. Also please post code, not images of code (in general) –  Mar 02 '22 at 10:37
  • Does this answer your question? [Node.js document is not defined](https://stackoverflow.com/questions/32126003/node-js-document-is-not-defined) –  Mar 02 '22 at 12:27

1 Answers1

1

In your screenshot, you're attempting to run the script using Node.js (the server-side JavaScript executable).

Since you say you're running live-server, you should be looking at your browser instead, not trying to run your code via Node.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • This is definitely a dupe –  Mar 02 '22 at 10:44
  • Dupe: https://stackoverflow.com/questions/32126003/node-js-document-is-not-defined –  Mar 02 '22 at 12:27
  • @ChrisG That's indeed a dupe of the question, but the accepted top answer alludes to using browserify, which wouldn't help OP at all. – AKX Mar 02 '22 at 12:40