# Autocompletion in Javascript nested in HTML

**URL:** <https://discuss.codemirror.net/t/autocompletion-in-javascript-nested-in-html/4038>\
**Category:** v6\
**Created:** [February 21, 2022, 11:13pm UTC](https://discuss.codemirror.net/t/autocompletion-in-javascript-nested-in-html/4038 "2022-02-21T23:13:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madd0g](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/madd0g/32/252_2.png) [@Madd0g](https://discuss.codemirror.net/u/Madd0g)\
**Post date:** [February 21, 2022, 11:13pm UTC](https://discuss.codemirror.net/t/autocompletion-in-javascript-nested-in-html/4038/1 "2022-02-21T23:13:34Z")

</div>

Following the official autocomplete [example](https://codemirror.net/6/examples/autocompletion/) I managed to get custom autocomplete working in HTML

However, when I tried the same approach inside script tags, it didn’t work, is that because it’s a nested mode? Any way to get it to fire?

```auto
import { javascriptLanguage } from '@codemirror/lang-javascript';
import { htmlLanguage } from '@codemirror/lang-html';

...
htmlLanguage.data.of({
    autocomplete: completeHtml,
}),
html(),
javascriptLanguage.data.of({
    autocomplete: completeJavascript,
}),
javascript({ jsx: false }), // I tried removing this too
...

```

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [February 22, 2022, 9:28am UTC](https://discuss.codemirror.net/t/autocompletion-in-javascript-nested-in-html/4038/2 "2022-02-22T09:28:01Z")

</div>

This should work (and works for me). Though the last call to `javascript` doesn’t do anything (only the highest-precedence top-level language is used). `html()` will automatically use `javascriptLanguage` for script content, so autocompletion there will consult the language data for `javascriptLanguage`.

One thing that you might want to check is whether you have multiple copies of `lang-javascript` in your node\_modules (`npm ls --all`). Language data works by identity, so if the `javascriptLanguage` package you import here is different from the one `lang-html` internally imports you might get a failure like this.

---

<div class="post-metadata">

**Author:** ![Madd0g](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/madd0g/32/252_2.png) [@Madd0g](https://discuss.codemirror.net/u/Madd0g)\
**Post date:** [February 22, 2022, 10:21am UTC](https://discuss.codemirror.net/t/autocompletion-in-javascript-nested-in-html/4038/3 "2022-02-22T10:21:43Z")

</div>

aha! you’re absolutely right, I have one in node\_modules and one under @codemirror/lang-html, I changed my import to this and now my callback fires!

```auto
import { javascriptLanguage } from '@codemirror/lang-html/node_modules/@codemirror/lang-javascript';

```
