WebReflection / WebReflection/linkedom
`document.querySelector()` doesn't return specific class
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 2.1k
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
For some elements, the document.querySelector() method doesn't return the specific class, but a HTMLElement. For example with the <meta> element whose object returned isn't an HTMLMetaElement.
import * as linkedom from 'linkedom';
const { document } = linkedom.parseHTML(`
<html>
<head>
<meta name="foo" content="bar">
</head>
<body>
<button>Baz/<button>
<span>Qux/span>
<a>Quux</a>
</body>
</html>
`);
console.log(document.querySelector("meta") instanceof linkedom.HTMLMetaElement); // false
console.log(document.querySelector("button") instanceof linkedom.HTMLButtonElement); // true
console.log(document.querySelector("span") instanceof linkedom.HTMLSpanElement); // false
console.log(document.querySelector("a") instanceof linkedom.HTMLAnchorElement); // true
Maybe the problem happens only on the class that doesn't call registerHTMLClass().
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with esm/shared/register-html-class.js and the document.querySelector() reproduction in the issue, comparing the handling of meta and span with button and a. Confirm which element classes are not registered. Done means the reported elements are returned as their specific linkedom classes and the instanceof checks pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100