Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot select element with duplicate id but different element class #116

Open
wilt00 opened this issue Jul 10, 2022 · 2 comments
Open

Cannot select element with duplicate id but different element class #116

wilt00 opened this issue Jul 10, 2022 · 2 comments

Comments

@wilt00
Copy link

wilt00 commented Jul 10, 2022

In the case where two different elements of different classes (e.g. div and img) share the same id:

import { DOMParser } from "https://deno.land/x/[email protected]/deno-dom-wasm.ts";
const h = '<div id="i"><img id="i"/></div>';
const d = new DOMParser().parseFromString(h, "text/html");
d.querySelectorAll('#i'); // only returns the div tag
d.querySelector('img#i'); // returns null

deno-dom is unable to select the second tag.

Firefox and Chrome are both able to select the img tag - see screenshot of Firefox's behavior below:

image
(Edit: replaced with a slightly more rigorous non-Quirks-mode screenshot)

Duplicating ids is banned by the spec, but can be found in the wild - e.g. Google sites like youtube.com make heavy usage of nonunique ids in shared components.

Tested with https://deno.land/x/[email protected]/deno-dom-wasm.ts

@b-fuze
Copy link
Owner

b-fuze commented Jul 14, 2022

This is likely an issue upstream with the nwsapi dependency... I'll have to look into why it's doing this 🤔

@jsejcksn
Copy link

FYI: A document's having multiple elements with the same ID is not spec (regardless of how an agent's runtime allows interactions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants