Why should one add ID to their HTML tags?

后端 未结 9 2063
日久生厌
日久生厌 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:36

    Well, in most cases id is used to do other things along side page navigation, which is very general. Some of the cute uses of id attribute are include

    1. A reference for scripts,Selecting elements to apply scripts to,
    2. A style sheet selector, selecting elements for styling
    3. Named anchors for linking to, which is what u called page navigation i guess

    So simply because in most cases you will want to do something to or with your content in any tag, its good to put an identifier, that is the id attribute.

提交回复
热议问题