It was found that there is a duplicate id attribute value "x" in the web page.
P粉905144514
P粉905144514 2023-08-31 16:06:41
0
2
557
<p>I'm using Angular 7 - three components [a, b, c] use an input element with id [x], however, component [b] also uses 4 inputs with id [x] element. This raises accessibility issues - since the id needs to be unique. The test case uses 'getElementById' to retrieve the value and expects certain results. </p> <p>Now what I did was changed these id selectors to classes - as I didn't need them to be unique and also changed the test case - 'querySelector'. </p> <p>Any ideas why I still get the same error as "Duplicate id attribute value 'x' found on web page"? </p>
P粉905144514
P粉905144514

reply all(1)
P粉662089521

From an accessibility perspective, WCAG 4.1.1 Parsing is the guideline on having unique IDs. The guide basically says you should have valid HTML, but it only lists four types of invalid HTML that can cause accessibility issues:

  1. " element has complete opening and closing tags,
  2. Elements are nested according to their specification,
  3. Elements do not contain duplicate attributes,
  4. and any ID is unique,"

There are many ways to generate invalid HTML, but these four can also cause accessibility issues. Note that any of these four issues means you have invalid HTML, so you may be facing problems beyond just accessibility issues. I think you don't want to have any invalid HTML.

So in your case you are seeing the fourth listed error. HTML specification states that IDs must be unique.

You mentioned:

If you have duplicate IDs, what do you expect to get from getElementById? The specification of getElementById says:

You also said:

Does this mean that no element has an ID? Do they all have classes? If you run an accessibility scanning tool and it flags errors about duplicate IDs, then obviously you didn't convert all the IDs to classes.

  • reply Right
    123333 author 2023-09-01 15:55:04
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template