Why should one add ID to their HTML tags?

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

    They're most often used to uniquely identify elements for styling (CSS) and scripting (JavaScript et al) purposes.

    But if you're asking about HTML and only HTML, then one example where declarative IDs are useful is associating a with its ,