If is obsolete, what is preferred?

后端 未结 5 2029
北海茫月
北海茫月 2020-12-30 19:24

The HTML code text is very useful for creating links to specific sections of a page (e.g., page.html#some_bookma

5条回答
  •  情深已故
    2020-12-30 20:08

    Have a look at the HTML5 spec.

    At Obsolete features you’ll find:

    Authors should not specify the name attribute on a elements.

    When clicking on name, you’ll find:

    [The following attributes are obsolete (though the elements are still part of the language), and must not be used by authors:]

    • name on a elements (except as noted in the previous section)
    • name on embed elements
    • name on img elements
    • name on option elements

    → Use the id attribute instead.

    Click on id. You’ll see that id is a global attribute, this means that it can be used on any element.

    The id attribute specifies its element's unique identifier (ID).
    […]
    Note: An element's unique identifier can be used for a variety of purposes, most notably as a way to link to specific parts of a document using fragment identifiers, as a way to target an element when scripting, and as a way to style a specific element from CSS.

提交回复
热议问题