Best practice for CSS class naming for use with jQuery selectors

前端 未结 6 2074
北恋
北恋 2020-12-28 15:55

While building a Javascript-heavy web application, what is the best practice for naming CSS classes to keep the Javascript code and CSS stylesheets clean and the UI structur

6条回答
  •  粉色の甜心
    2020-12-28 16:54

    That's a very good question. I think your first option (name every single element uniquely) is the right one, because:

    • The element classes (not names) are not that long,
    • Emphasis is made on the group as a whole anyway, so the HTML structure of the group should not change very often, and
    • Defects in the UI structure can be spotted more easily that way.

    That said, I would use a slightly different markup:

提交回复
热议问题