Can an html element have multiple ids?

前端 未结 18 2530
天命终不由人
天命终不由人 2020-11-22 07:40

I understand that an id must be unique within an HTML/XHTML page.

My question is, for a given element, can I assign multiple ids to it?

18条回答
  •  遥遥无期
    2020-11-22 07:59

    No, you should use nested DIVs if you want to head down that path. Besides, even if you could, imagine the confusion it would cause when you run document.getElementByID(). What ID is it going to grab if there are multiple ones?

    On a slightly related topic, you can add multiple classes to a DIV. See Eric Myers discussion at,

    http://meyerweb.com/eric/articles/webrev/199802a.html

提交回复
热议问题