X
X
xonar2019-07-14 23:51:40
JavaScript
xonar, 2019-07-14 23:51:40

Why doesn't JS work in visual code?

Hello. There is a working code, but in VS Code + open live server it doesn't work. More precisely, javascript does not work at all

var login = document.querySelector(".login-link");
    var loginpopup = document.querySelector(".modal-login");
    
    login.addEventListener("click", function (event) {
        event.preventDefault();
        loginpopup.classList.add("modal-show");
    });

UPD. It works in codepen, but on LAN, through browser synchronization with VS code, it throws a link. Faced with this? Maybe something needs to be included in VS code?
UPD 2.0. I installed a debugger in VS code and it gave this.
var login = document.querySelector('.login-link');
^
ReferenceError: document is not defined
at Object. (h:\barbershop\modal.js:1:13)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader .js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load ( internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

But, again, the code is working. You can look here for a working version - https://codepen.io/ruslan-lysenko/pen/rEgqBe
Soon I'll be crazy and switch to notepad++

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-07-15
@AlexanderK-A

Good day!
It doesn't appear that your html page is linking to a js file: Apparently codepen does this automatically.

V
VegasChickiChicki, 2019-07-15
@VegasChickiChicki

Turn off what is doing the file synchronization and updating, and then try to do what you are trying.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question