admin管理员组

文章数量:1289911

I think the answer is probably "no," but I wanted to get the opinion of people who know a lot more than me. Can you use the "id" attribute with HTML elements in the head section, such as title or link? The purpose would be to change their values with JavaScript. Thanks in advance.

I think the answer is probably "no," but I wanted to get the opinion of people who know a lot more than me. Can you use the "id" attribute with HTML elements in the head section, such as title or link? The purpose would be to change their values with JavaScript. Thanks in advance.

Share Improve this question asked Jan 13, 2016 at 17:15 freginoldfreginold 3,9563 gold badges15 silver badges29 bronze badges 2
  • You can, what are you trying to do? – Pavel Durov Commented Jan 13, 2016 at 17:18
  • Possible duplicate of Is it okay to add id/class to <link> tag? – Drew Kennedy Commented Jan 13, 2016 at 17:19
Add a ment  | 

3 Answers 3

Reset to default 15

Yes. All HTML elements support the ID attribute.

See the spec:

The following attributes are mon to and may be specified on all HTML elements (even those not defined in this specification):

  • id

Yup. Every html element supports an id:

<head id="everyone"/>

The id attribute is a Global Attribute

Yes, you can use an id attribute in a head element. Further, here is the full list of Global Attributes and they may be specified on all HTML elements.

  • accesskey
  • class
  • contenteditable
  • dir
  • hidden
  • id
  • lang
  • spellcheck
  • style
  • tabindex
  • title
  • translate

本文标签: javascriptCan you use IDs with HTML head tagsStack Overflow