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.

Ben
  • 10,020
  • 21
  • 94
  • 157
  • Why is this a warning in the first place? `document` has been defined. Is this a bug in JSLint? – jfriend00 Aug 17 '11 at 09: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 Aug 17 '11 at 09:49

6 Answers6

56

You can simply use

/*jslint browser:true */

in the beginning of the code to assume a browser.

Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92
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.

Emil Ivanov
  • 37,300
  • 12
  • 75
  • 90
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.

Mikhail
  • 8,692
  • 8
  • 56
  • 82
4

Use the shorthand:

$(function() {
   ...
});
Andrew Duffy
  • 6,800
  • 2
  • 23
  • 17
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

equiman
  • 7,810
  • 2
  • 45
  • 47