Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery intellisense in VS Code

I have tried this:

JQuery intellisense in Visual Studio Code

and this:

http://shrekshao.github.io/2016/06/20/vscode-01/

But it does nothing, VS Code just won't add jquery intellisense, I've been trying to solve this for hours but it just won't work

like image 446
Lisgaira Avatar asked Jan 21 '17 08:01

Lisgaira


People also ask

Can I use jQuery in Visual Studio code?

Use any text editor to write jQuery script e.g. Notepad, Visual Studio, Eclipse, Aptana studio etc. Download the appropriate version of jQuery from jQuery.com. Include jQuery library using <script> tag. You can also include jQuery library from public CDN with fall back mechanism e.g code.jquery.com.

How do I enable IntelliSense in Visual Studio?

To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.


3 Answers

Most of the blog postings are now outdated, as we finally have automatic type acquisition with version 1.8+ - you no longer need to install the typings yourself.

I recommend reading the official documentation, its always up to date: https://code.visualstudio.com/docs/languages/javascript

If you use npm and have a package.json in your project and jQuery is listed there, it should already work.

If you do not use npm, you can create the file jsconfig.json in the project root with the following content and you are good to go:

{     "typeAcquisition": {         "include": [             "jquery"         ]     }  } 
like image 124
kwood Avatar answered Oct 03 '22 11:10

kwood


Type this command in your project root :

npm i --save @types/jquery 
like image 33
Wong Jia Hau Avatar answered Oct 03 '22 13:10

Wong Jia Hau


I had the same problem and google brought me here. I added the type jsconfig.json and "typeAcquisition" and still nothing.

Turns out you have to have node and npm installed. Even if you are not using them for package management and are importing jquery from a CDN.

From the Docs

Many popular libraries ship with typings files so you get IntelliSense for them automatically. For libraries that do not include typings, VS Code's Automatic Type Acquisition will automatically install community maintained typings file for

Automatic type acquisition requires npmjs, the Node.js package manager, which is included with the Node.js runtime. In this image you can see IntelliSense, including the method signature, parameter info, and the method's documentation for the popular lodash library.

https://code.visualstudio.com/docs/nodejs/working-with-javascript

So vs code uses npm for auto type acquisition.

May be super basic, but it solved my problem so I hope it helps someone else too.

I also used the configuration in jsconfig.json as described by kwood. Not sure I needed to specify it manually after installin npm but it is working so i'm not asking questions

like image 25
Ben Avatar answered Oct 03 '22 13:10

Ben