Why should one add ID to their HTML tags?

后端 未结 9 2043
日久生厌
日久生厌 2020-11-29 14:16

A simple question: why should we add the id into our HTML tags if they work perfectly well without them? I know that one of their uses is being able to navigate

9条回答
  •  攒了一身酷
    2020-11-29 14:47

    I myself also prefer class for styling through CSS but sometimes you need an element to be unique. For accessibility reasons you use id to input elements to "connect" its label to it by using for attribute. And for Javascript it's much simpler to select an element if it has got id attribute.

提交回复
热议问题