What are the common solutions for making clean id space in a SPA?

后端 未结 7 2195
感情败类
感情败类 2021-02-14 05:05

Situation: several developers working remotely on different section/modules of a SPA. As a result they may accidentally introduce HTML elements with the same id. W

7条回答
  •  时光取名叫无心
    2021-02-14 05:25

    I would prefer to see ids used only to specify modules, widgets, main sections etc. This will lead less id's in general and most of your naming to be created by your business logic. You also end up structuring your classes & tags with a sort of localised hierarchy like: #specialWidget h3 {} #specialWidget p {} and you just select your handlers like - $('#specialWidget .some-btn').click() and never like $('#someBtn').click() because it just get's messy and too specific.

    Past that, testing and continuous integration are your best bet to catch things like this.

提交回复
热议问题