Jump to content

Help:Lint errors/duplicate-ids

From mediawiki.org

An element's id attribute value is intended to be unique in the document. Lint errors in this category highlight instances where the same id attribute value is being used on multiple elements in the page.

Example

[edit]
<div id="test">123</div>

<p>hmm</p>

<div id="test">456</div>

The ID test is duplicated.

Do not use duplicate IDs

[edit]

HTML documents should not be using duplicate IDs on elements. If your CSS or Javascript code targets elements with an ID, where you expect multiple elements on a page to get the same ID, use a CSS class instead to target them (or use other CSS selectors where applicable).

Example

[edit]

An edit of a template to add a class on an element and the corresponding edit of Javascript to target the class.

History

[edit]

This Lint error was first requested in task T200517. However, the impetus for implementing it now is the Parser Unification project. Parsoid, the new wikitext parser, enforces deduplication of element IDs where necessary - this is a change from how the legacy wikitext parser does things. Fixing these errors is requested of editors since it can improve rendering compatibility when Parsoid is enabled on a wiki.