Javascript “document” is not defined
I am studing javascript but console say's: document is not defined
.
In this code:
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click'), function(){
nav.classList.toggle('show');
})
I dont know what is wrong, can you help me?
javascript html css
add a comment |
I am studing javascript but console say's: document is not defined
.
In this code:
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click'), function(){
nav.classList.toggle('show');
})
I dont know what is wrong, can you help me?
javascript html css
5
Where are you running this code?
– SLaks
Nov 25 '18 at 18:11
1
Possible duplicate of ReferenceError: document is not defined (in plain JavaScript)
– Ole EH Dufour
Nov 25 '18 at 18:11
If you use node to execute your JavaScript there is no document, as there is no website...
– Daniel Habenicht
Nov 25 '18 at 18:12
add a comment |
I am studing javascript but console say's: document is not defined
.
In this code:
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click'), function(){
nav.classList.toggle('show');
})
I dont know what is wrong, can you help me?
javascript html css
I am studing javascript but console say's: document is not defined
.
In this code:
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click'), function(){
nav.classList.toggle('show');
})
I dont know what is wrong, can you help me?
javascript html css
javascript html css
edited Nov 25 '18 at 18:09
JustLearning
1,23221637
1,23221637
asked Nov 25 '18 at 18:07
David Martinez PiedrabuenaDavid Martinez Piedrabuena
4
4
5
Where are you running this code?
– SLaks
Nov 25 '18 at 18:11
1
Possible duplicate of ReferenceError: document is not defined (in plain JavaScript)
– Ole EH Dufour
Nov 25 '18 at 18:11
If you use node to execute your JavaScript there is no document, as there is no website...
– Daniel Habenicht
Nov 25 '18 at 18:12
add a comment |
5
Where are you running this code?
– SLaks
Nov 25 '18 at 18:11
1
Possible duplicate of ReferenceError: document is not defined (in plain JavaScript)
– Ole EH Dufour
Nov 25 '18 at 18:11
If you use node to execute your JavaScript there is no document, as there is no website...
– Daniel Habenicht
Nov 25 '18 at 18:12
5
5
Where are you running this code?
– SLaks
Nov 25 '18 at 18:11
Where are you running this code?
– SLaks
Nov 25 '18 at 18:11
1
1
Possible duplicate of ReferenceError: document is not defined (in plain JavaScript)
– Ole EH Dufour
Nov 25 '18 at 18:11
Possible duplicate of ReferenceError: document is not defined (in plain JavaScript)
– Ole EH Dufour
Nov 25 '18 at 18:11
If you use node to execute your JavaScript there is no document, as there is no website...
– Daniel Habenicht
Nov 25 '18 at 18:12
If you use node to execute your JavaScript there is no document, as there is no website...
– Daniel Habenicht
Nov 25 '18 at 18:12
add a comment |
1 Answer
1
active
oldest
votes
I have tested your code in JsFiddle and you have a bug a parenthesis not needed after 'click'
.
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click', function(){
nav.classList.toggle('show');
})
.show {
width: 250px;
height: 100px;
background-color: red;
text-align: center;
font-size: 35px;
color: blue;
}
<div><input type ="submit" id="btn-menu" value="Menu Button"/>
<nav id="nav">The nav</nav>
</div>
So I have added html tags that refer to your code and also added some css code that needed to se the changes from the button when clicked.
Note. This is just an example how can you work with addEventListener
and classList.toggle
and making your piece of code working.
I know you mentioned that at the end of your answer, but the OP problem is something else
– Colin Cline
Nov 25 '18 at 20:23
I changed just the)
and code works.
– Llazar
Nov 25 '18 at 20:26
Problem isdocument
is not defined. If this happens when the user clicks, your answer is right not when the user just runs it. You run your code in the right environment. Problem is OP doesn't know in which environment he is running his code.
– Colin Cline
Nov 25 '18 at 20:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470385%2fjavascript-document-is-not-defined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have tested your code in JsFiddle and you have a bug a parenthesis not needed after 'click'
.
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click', function(){
nav.classList.toggle('show');
})
.show {
width: 250px;
height: 100px;
background-color: red;
text-align: center;
font-size: 35px;
color: blue;
}
<div><input type ="submit" id="btn-menu" value="Menu Button"/>
<nav id="nav">The nav</nav>
</div>
So I have added html tags that refer to your code and also added some css code that needed to se the changes from the button when clicked.
Note. This is just an example how can you work with addEventListener
and classList.toggle
and making your piece of code working.
I know you mentioned that at the end of your answer, but the OP problem is something else
– Colin Cline
Nov 25 '18 at 20:23
I changed just the)
and code works.
– Llazar
Nov 25 '18 at 20:26
Problem isdocument
is not defined. If this happens when the user clicks, your answer is right not when the user just runs it. You run your code in the right environment. Problem is OP doesn't know in which environment he is running his code.
– Colin Cline
Nov 25 '18 at 20:36
add a comment |
I have tested your code in JsFiddle and you have a bug a parenthesis not needed after 'click'
.
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click', function(){
nav.classList.toggle('show');
})
.show {
width: 250px;
height: 100px;
background-color: red;
text-align: center;
font-size: 35px;
color: blue;
}
<div><input type ="submit" id="btn-menu" value="Menu Button"/>
<nav id="nav">The nav</nav>
</div>
So I have added html tags that refer to your code and also added some css code that needed to se the changes from the button when clicked.
Note. This is just an example how can you work with addEventListener
and classList.toggle
and making your piece of code working.
I know you mentioned that at the end of your answer, but the OP problem is something else
– Colin Cline
Nov 25 '18 at 20:23
I changed just the)
and code works.
– Llazar
Nov 25 '18 at 20:26
Problem isdocument
is not defined. If this happens when the user clicks, your answer is right not when the user just runs it. You run your code in the right environment. Problem is OP doesn't know in which environment he is running his code.
– Colin Cline
Nov 25 '18 at 20:36
add a comment |
I have tested your code in JsFiddle and you have a bug a parenthesis not needed after 'click'
.
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click', function(){
nav.classList.toggle('show');
})
.show {
width: 250px;
height: 100px;
background-color: red;
text-align: center;
font-size: 35px;
color: blue;
}
<div><input type ="submit" id="btn-menu" value="Menu Button"/>
<nav id="nav">The nav</nav>
</div>
So I have added html tags that refer to your code and also added some css code that needed to se the changes from the button when clicked.
Note. This is just an example how can you work with addEventListener
and classList.toggle
and making your piece of code working.
I have tested your code in JsFiddle and you have a bug a parenthesis not needed after 'click'
.
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click', function(){
nav.classList.toggle('show');
})
.show {
width: 250px;
height: 100px;
background-color: red;
text-align: center;
font-size: 35px;
color: blue;
}
<div><input type ="submit" id="btn-menu" value="Menu Button"/>
<nav id="nav">The nav</nav>
</div>
So I have added html tags that refer to your code and also added some css code that needed to se the changes from the button when clicked.
Note. This is just an example how can you work with addEventListener
and classList.toggle
and making your piece of code working.
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click', function(){
nav.classList.toggle('show');
})
.show {
width: 250px;
height: 100px;
background-color: red;
text-align: center;
font-size: 35px;
color: blue;
}
<div><input type ="submit" id="btn-menu" value="Menu Button"/>
<nav id="nav">The nav</nav>
</div>
var btnMenu = document.getElementById('btn-menu');
var nav = document.getElementById('nav');
btnMenu.addEventListener('click', function(){
nav.classList.toggle('show');
})
.show {
width: 250px;
height: 100px;
background-color: red;
text-align: center;
font-size: 35px;
color: blue;
}
<div><input type ="submit" id="btn-menu" value="Menu Button"/>
<nav id="nav">The nav</nav>
</div>
answered Nov 25 '18 at 19:47
LlazarLlazar
1,0561717
1,0561717
I know you mentioned that at the end of your answer, but the OP problem is something else
– Colin Cline
Nov 25 '18 at 20:23
I changed just the)
and code works.
– Llazar
Nov 25 '18 at 20:26
Problem isdocument
is not defined. If this happens when the user clicks, your answer is right not when the user just runs it. You run your code in the right environment. Problem is OP doesn't know in which environment he is running his code.
– Colin Cline
Nov 25 '18 at 20:36
add a comment |
I know you mentioned that at the end of your answer, but the OP problem is something else
– Colin Cline
Nov 25 '18 at 20:23
I changed just the)
and code works.
– Llazar
Nov 25 '18 at 20:26
Problem isdocument
is not defined. If this happens when the user clicks, your answer is right not when the user just runs it. You run your code in the right environment. Problem is OP doesn't know in which environment he is running his code.
– Colin Cline
Nov 25 '18 at 20:36
I know you mentioned that at the end of your answer, but the OP problem is something else
– Colin Cline
Nov 25 '18 at 20:23
I know you mentioned that at the end of your answer, but the OP problem is something else
– Colin Cline
Nov 25 '18 at 20:23
I changed just the
)
and code works.– Llazar
Nov 25 '18 at 20:26
I changed just the
)
and code works.– Llazar
Nov 25 '18 at 20:26
Problem is
document
is not defined. If this happens when the user clicks, your answer is right not when the user just runs it. You run your code in the right environment. Problem is OP doesn't know in which environment he is running his code.– Colin Cline
Nov 25 '18 at 20:36
Problem is
document
is not defined. If this happens when the user clicks, your answer is right not when the user just runs it. You run your code in the right environment. Problem is OP doesn't know in which environment he is running his code.– Colin Cline
Nov 25 '18 at 20:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470385%2fjavascript-document-is-not-defined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
5
Where are you running this code?
– SLaks
Nov 25 '18 at 18:11
1
Possible duplicate of ReferenceError: document is not defined (in plain JavaScript)
– Ole EH Dufour
Nov 25 '18 at 18:11
If you use node to execute your JavaScript there is no document, as there is no website...
– Daniel Habenicht
Nov 25 '18 at 18:12