How can I enable IntelliSense for JavaScript inside HTML?
Asked Answered
A

6

30

I want to use VS Code to try out the examples of a JavaScript book, but there's no IntelliSense, or at least I don't know how to activate it.

In Visual Studio this feature works out of the box :

enter image description here

But in VS Code, all I got is a message saying "No suggestions."

enter image description here

What do I need to do to enable IntelliSense in VS Code?

Annis answered 5/5, 2016 at 16:15 Comment(0)
R
8

Currently Unsupported

JS intellisense doesnt work in HTML script tag - VSCode GitHub Issues #4369

Smart Javascript suggestions inside HTML files no loger working after Visual Studio Code update - StackOverflow

Recess answered 6/5, 2016 at 23:38 Comment(3)
sad but it's true :(Annis
It's supported from version 1.8, please see my answer below.Gwenny
@Axel: not sad, and not true — see the answer below https://mcmap.net/q/477526/-how-can-i-enable-intellisense-for-javascript-inside-htmlDecahedron
G
8

Starting with the November 2016 (version 1.8) release, Visual Studio Code now fully supports IntelliSense for JavaScript in HTML.

Note that the language support doesn't follow script includes, it only knows about definitions made in the same file.

Gwenny answered 8/3, 2017 at 7:46 Comment(0)
M
2

It worked for me, when the file had a .js extension. I didn't get any intellisense when I pasted it into .html file between script tags.

Edit To Add: You can also change the Language Mode by clicking 'HTML' in the bottom of the VS Code window and change it to 'JavaScript'.

Mablemabry answered 6/5, 2016 at 1:44 Comment(2)
That's not a working solution for me. Should be able to have both html and javascript intellisense in one file, as for html files this is fairly common.Builder
It appears that currently this feature is no longer supported since the adoption of Salsa.Recess
D
2

It is supported!

Intellisense and syntax highlighting start working after replacing

<script>something()</script>

with

<script type="text/javascript">something()</script>
Decahedron answered 2/9, 2021 at 22:18 Comment(1)
Simple and easy. Best solution so far.Veteran
D
0

Make sure you have HTML language mode selected in the bottom right corner. I had Markdown mode set for an unknown reason (autodetect?) and it didn't work for me. Javascript mode won't work either for HTML files.

HTML language mode selected

Delicate answered 6/12, 2022 at 13:48 Comment(0)
S
-5

Visual Studio Code version 1.4.0 does not support CSS intelli-sense.

I have an extension for CSS style, id and class intelli-sense for html documents:

Features:

  • Style tag completion and hover.
  • Style attribute completion and hover.
  • Id attribute completion.
  • Class attribute completion.
  • Scans workspace folder for css files.
  • Supports optional resource.json file for fine tuned resource selection.

Link:

https://marketplace.visualstudio.com/items?itemName=ecmel.vscode-html-css

Sachsse answered 16/8, 2016 at 6:38 Comment(1)
At least understand the question before self-promoting.Consonantal

© 2022 - 2024 — McMap. All rights reserved.