18

I get a

'document' has not been fully defined yet.
    $(document).ready(function () {

warning from jsLint. I get why this happends but I would like my code to be warning free.

My question is - how do I either solve this in code (assign document to itself? var document=document?) or maybe make the warning go away some other way.

Thanks.

2
  • Why is this a warning in the first place? document has been defined. Is this a bug in JSLint?
    – jfriend00
    Commented Aug 17, 2011 at 9:41
  • because, if I understand correctly, the use occurs within the definition of document. I.E - the variable is used inside its definition. similar to var x = 3 + x;
    – Ben
    Commented Aug 17, 2011 at 9:49

6 Answers 6

56

You can simply use

/*jslint browser:true */

in the beginning of the code to assume a browser.

0
11

I think you can safely ignore that. If you don't want it to show anyway, rewrite it like so

$(function () {
    // Document is ready
});

$(function () {}) and $(document).ready(function () {}) are equivalent.

4

Use the shorthand:

$(function() {
   ...
});
0
4

If you prefer to keep your code the way you have it, you can tell JSlint to be OK with your decision:

/*global document*/
$(document).ready(function () {
    ...
}

This indicates that document has been defined elsewhere.

0
1

JSLint requires that you assume a browser in the selector options. the document will be defined then. Using $ will not help here...not in JSLint anyway.

0

create an .jsintrc on root folder, with this:

{ "browser": true }

You can see all options in JSHint Options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.