0

Why are all my jQuery selectors highlighted like this? If there is nothing wrong with the syntax I don't want it highlighted.

enter image description here

11
  • you may have another plugin installed that sees the Jquerys ids as annotation. But this should be just a warrning or just info.
    – Edwin
    Commented Jun 29, 2017 at 14:32
  • What other plugins might cause this behavior? Is there a way to find out?
    – user736893
    Commented Jun 29, 2017 at 14:37
  • Are you concerned with why they have the "Annotate injection with comment" context option, or that they are highlighted? Because those are actually separate from each other.
    – phaze0
    Commented Jun 29, 2017 at 14:37
  • you can see your plugins under File->Settings->Plugins. As well you can go under File->Settings->Editor->Inspections to check all of your inspections and then enable/disable the ones you need.
    – Edwin
    Commented Jun 29, 2017 at 14:38

1 Answer 1

2

So the highlighting is because of the theme you are using, as injected languages can be styled differently to let you know they will be highlighted with a different language theme than the main one in the file. It's possible to turn off the highlighting, though I've not found a way to turn off jQuery language injection yet.

File → Settings → Editor > Colors & Fonts > General
Then expand the "Code" section and select "Injected language fragment". Here you can turn off the "Background" effect to remove the highlighting you are seeing. Keep in mind, the injected language will still be highlighted in that language's theme, so you might just want to change the background or add an effect on it (I for one have it bordered with no background).

example

Depending on your version of IntelliJ, you may have to save a copy of the default theme first because they didn't always let you overwrite the built in ones.

5
  • This is a great workaround, thanks. I'd still like to know why it thinks it's a "fragment"?
    – user736893
    Commented Jun 29, 2017 at 14:57
  • 2
    @RatherNotsay, it's because jQuery selectors use CSS, so it's using the CSS colors&fonts settings to highlight it separately from the JS settings.
    – phaze0
    Commented Jun 29, 2017 at 14:59
  • I see. Is this generally acceptable? The only way around it I found was to define the selector as a string first then use $(selector).
    – user736893
    Commented Jun 29, 2017 at 15:02
  • You might find that IntelliJ will still occasionally inject highlighting on even your separated selector value if it recognizes that it is only used in selectors (it does the same with SQL for me in some cases). And unfortunately it doesn't look like there is any support to turn off injection on jquery selectors.
    – phaze0
    Commented Jun 29, 2017 at 15:11
  • 1
    IDEA automatically injects CSS in jQuery calls to provide completion for CSS selectors there. there is no way to disable this injection currently, youtrack.jetbrains.com/issue/WEB-8191.
    – lena
    Commented Jun 29, 2017 at 15:18