Why should one add ID to their HTML tags?

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

    Uses of id attributes in HTML

    • As a target for a fragment identifier on a URL.
    • As a target on form controls for the for attribute on and elements.
    • As a target on
      elements for the form attribute on form associated elements.
    • As a target for element references via the microdata itemref attribute.
    • As a target for element references via some ARIA attributes including aria-describedby, aria-labelledby and 4 others.
    • As a target on elements for the headers attribute on and elements.
    • As a target on elements for the contextmenu attribute.
    • As a target on elements for the list attribute on elements.
    • As part of a hash-name reference to elements for the usemap attribute on the and elements.
    • As an identifier of an element in a CSS selector
    • As an identifier of an element for JavaScript processing
    • 提交回复
      热议问题