Why are all my jQuery selectors highlighted like this? If there is nothing wrong with the syntax I don't want it highlighted.
1 Answer
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).
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.
-
This is a great workaround, thanks. I'd still like to know why it thinks it's a "fragment"?– user736893Commented 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.– phaze0Commented 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)
.– user736893Commented 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.– phaze0Commented Jun 29, 2017 at 15:11
-
1IDEA 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.– lenaCommented Jun 29, 2017 at 15:18
File->Settings->Plugins
. As well you can go underFile->Settings->Editor->Inspections
to check all of your inspections and then enable/disable the ones you need.