I am using brackets editor for code editing. I have already installed a brackets extension "js lint". For DOM element I have to write document.getElemenstById
or other DOM syntax. JS lint shows an error "document is not defined". So please tell me what is the syntax for define document in JS?
I am using brackets editor for code editing. I have already installed a brackets extension "js lint". For DOM element I have to write document.getElemenstById
or other DOM syntax. JS lint shows an error "document is not defined". So please tell me what is the syntax for define document in JS?
- 1 "Assume a browser?" i.sstatic/ch78U.png – Matt Ball Commented Jan 3, 2018 at 19:13
-
4
document
is something provided by the browser runtime environment, so unless your linter has a mode that accounts for that it won't be defined. – tadman Commented Jan 3, 2018 at 19:13 -
1
In addition to @tadman above, it's
document.getElementById
, notdocument.getElemenstById
becauseid
s should be unique within a document, so you should never find two with the sameid
. – Scott Marcus Commented Jan 3, 2018 at 19:23
2 Answers
Reset to default 3JavaScript is a language with its own syntax and built in types. document
is not defined in the JavaScript (also more formally known as ECMAScript) specification. document
is provided as an object API by the JavaScript "host" environment, which in a web page scenario, is the user agent (also known as the browser). Modern browser's supply a wide range of objects to the JavaScript runtime and your linter is not likely to advise you about them. However, there is a standard for the document
API called the Document Object Model, which is maintained by the World Wide Web Consortium (W3C), who sets many standards for the web.
To make a little more sense out of this, there is a very popular server-side application called Node JS. Node contains a full JavaScript runtime that conforms to the ECMAScript standard. But Node is a mand line, server-side application, not a browser. You don't execute web pages in Node, so there would never be a need for a document
object. Thankfully, JavaScript doesn't define a document
object, so all is well.
A quick way to remove all the JS Lint markers for "document is not defined" is to put "var document;" at the top of your JS file, just so you can see more clearly what the real errors are.
Do not leave "var document;" within the JS file though as it can cause problems.
I hope that makes things easier for you.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744807384a4594858.html
评论列表(0条)