WebReflection / WebReflection/linkedom

`document.querySelector()` doesn't return specific class

Open
#184 7 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.