2

enter image description here

How do I ignore this error. I have used the id attribute for some tags in order to reference them by id in javascript, but it shows this error:

CSS id selector '...' not found.

Please tell me how to ignore or disable this error.

Ezequiel Muns
  • 7,492
  • 33
  • 57

2 Answers2

0

maybe your css is not formatted properly.

try:

<style>
#phone {
your css here;
}
</style>

You need to make sure you mark the code with # to show that it's an id and not a class or something else.

wnetMC
  • 175
  • 8
0

Update: First section of answer no longer valid as of the lastest updates since original post which removed the css.validation option. see


If you are using the HTML CSS Support extension by ecmel, you can go to .vscode/settings.json and add

"css.validation": {
    "id": false,
    "class": false
}

This will turn off css validation for class name and id.

More information on this at the Visual Studio MarketPlace for this extension under Selector Validation here or the Github repository readme Selector Validation Section


Note: 1) Also don't forget to add a comma after the setting that comes before (as JSON format is comma separated).

Example:

{
    "java.codeGeneration.generateComments": true,
    "css.styleSheets": [
        // (1)
        "https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css",
        "src/main/resources/static/css/styles.css"
    ],
    "css.validation": {
        "id": false,
        "class": true
    }
}
  1. Sometimes you need to restart / close and reopen vscode after saving changed to the file for them take effect.

  2. There is a way to configure styleSheets. This next bit is taken from their documentation see Additional Styles Section:

Additional Style Sheets

If it is not possible to specify local or remote styles in HTML or via template inheritance, they can be specified in VS Code settings per workspace folder in .vscode/settings.json and will suggest for all HTML files within that workspace folder:

.vscode/settings.json

"css.styleSheets": [

    // (1)
    "https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css",

    // (2)
    "/site.css",

    // (3)
    "site.css",

    // (4)
    "./site.css" 
]

Zach
  • 880
  • 5
  • 17