Skip to content

.closest('#null') or .closest('.null') returns self #3466

@mirka

Description

@mirka

Basic info:

  • Node.js version: 14.19.3
  • jsdom version: 20.0.3

Minimal reproduction case

"null" selectors like #null and .null that shouldn't match anything are matching the original node when queried with .closest().

const { JSDOM } = require('jsdom');

const { window } = new JSDOM(`<p>foo</p>`);
const p = window.document.querySelector('p');

// These return null, as expected
console.log(p.closest('#whatever'));
console.log(p.closest('.whatever'));

// These return the HTMLParagraphElement
console.log(p.closest('#null'));
console.log(p.closest('.null'));

How does similar code behave in browsers?

Returns null when there is no match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    has to-upstream testThis bug has a failing to-upstream web platform test waiting to be fixedmetr upliftA candidate for the METR Uplift experimentselectorsCSS Selectors support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions