Should I make HTML Anchors with 'name' or 'id'?

前端 未结 14 1223
旧巷少年郎
旧巷少年郎 2020-11-22 00:49

When one wants to refer to some part of a webpage with the \"http://example.com/#foo\" method, should one use

F

14条回答
  •  无人共我
    2020-11-22 01:39

    Heads up for JavaScript users: all IDs become global variables under window.

    Foo Title

    Just created the JS global:

    window.foo
    

    The value of window.foo will be the HTMLElement for the h1.

    Unless you can guarantee all values used in id attributes are safe, you may prefer sticking to name:

    Foo Title

提交回复
热议问题