I read that the class and id correct to write like this: color-picker selected-color , it is wrong like this color_picker selected_color .

But when writing to js, ​​it's pretty convenient to use dash-free recordings.

 color_picker.style.display = "" 

Recently I saw that they were still writing in this way:

 class="colorPicker" id="selectedColor" 

How much is it right? And in general, what should I use?

Very grateful for understandable answers, especially with explanations.

Closed due to the fact that it is necessary to reformulate the question so that you can give an objectively correct answer to the participants of the D-side , aleksandr barakin , Nofate 17 Nov '16 at 11:18 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

3 answers 3

How to name usually depends on the preferences of the programmer or how it is accepted in the team, but the main thing is that everything in the project is the same, and not so that in each place it is different.

Look at the BEM naming methodology https://ru.bem.info/methodology/naming-convention/

In general, about the programming style on js https://github.com/airbnb/javascript

    I advise you to read about the BEM structure , which many have been using recently.

      Correct - this is how the specification permits. The specification does not specify in any way how the names of classes and identifiers should be compiled, setting only valid characters.

      Thus - all the options are correct .

      Which approach to use and for what, everyone defines himself.
      The choice may also be subject to the rules adopted in a particular group.

      • one
        Will you take me to yourself if I write like this - Ka__-_-_koЙ---tО-seЛе--___----_Ktoр ? Or do you want to say that some team can make you write like that? Yes, you need to be the last person on the planet earth to agree to write or say so correctly ..... - user220409
      • one
        @OlmerDale, I would look at a person who can write a lot of code with such selectors. Perhaps this is an undiscovered talent whose energy can be channeled for peaceful purposes = D - Duck Learns to Cover
      • 3
        @OlmerDale Вы возьмете меня к себе если я буду писать так - if the team at the company makes writing so, then yes - they will)) And also if you go to a company that has some kind of code rules that you absolutely need if you don't like it, then you can easily quit and go to another. But, be that as it may, since symbols are allowed, then you can write whatever your heart desires, and organize your rules for naming selectors. The law is not prohibited. - Alexey Shimansky
      • Yes, you need to be the last person on the planet earth to agree to write or say that it is so right - and are there any arguments that this is wrong ? - Grundy