Is it okay to add id/class to <link> tag?

前端 未结 4 456
孤独总比滥情好
孤独总比滥情好 2020-12-05 06:41

Is it okay to do this?


so I can use JavaScript to d

相关标签:
4条回答
  • 2020-12-05 07:10

    Yup, it is. It is not recommended though, as this'd mean loading several files (multiple HTTP requests) as opposed to loading one bigger file (but one HTTP request only).

    0 讨论(0)
  • 2020-12-05 07:26

    According to HTML 4.01 Transitional, id, class are document-wide selectors, and thus it is ok to have them in the link element.

    0 讨论(0)
  • 2020-12-05 07:31

    Yes, you can. The core attributes are allowed on the <link> element, which includes style, class, id, and title. Although, since it's not a rendered element, classes and styles won't have any effect.

    <!ENTITY % coreattrs
     "id          ID             #IMPLIED  -- document-wide unique id --
      class       CDATA          #IMPLIED  -- space-separated list of classes --
      style       %StyleSheet;   #IMPLIED  -- associated style info --
      title       %Text;         #IMPLIED  -- advisory title --"
      >
    
    0 讨论(0)
  • 2020-12-05 07:31

    Yes. There are certain attributes that may be specified on every html element. id and class are among them.

    For a complete list in the html5 spec: http://developers.whatwg.org/elements.html#global-attributes

    The spec for the link element: http://developers.whatwg.org/semantics.html#the-link-element

    And in html4.1: http://www.w3.org/TR/html401/struct/links.html#h-12.3

    0 讨论(0)
提交回复
热议问题