Skip to main content
HTML Bug Hunt Hard +35 XP

Duplicate IDs

JavaScript only finds one of these elements.

HTMLFind the bug
1<div id="card">Product 1</div>
2<div id="card">Product 2</div>
The bug is on line 2

Select the correct fix

Show answer and explanation

Answer: Use unique IDs or use class instead

IDs must be unique per page. document.getElementById() only returns the first match. Use classes for multiple elements.

Hint: IDs must be unique in a document.

What this challenge tests

Bug Hunt in HTML: ids, dom.

Related challenges