Best Practice for Naming the Id Attribute of Dom Elements

前端 未结 5 1455
半阙折子戏
半阙折子戏 2021-02-04 03:14

This is related to naming conventions for a DOM element\'s id attribute and I guess the name attribute as well. When it comes to JavaScript, from what I understand and have done

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 03:28

    Here are some naming guidelines that have helped me out with my ids and classes in the DOM:

    • don't include the type in the name (ie, no txt or chk). I can select that info using CSS or jQuery much more descriptivlely
    • use underscores as separators in the name. Hyphens don't always work out in other languages, and camel casing is a little tough to read in markup

提交回复
热议问题