Skip to content

Implement HTMLFormElement indexed getter #3616

Description

@daleconboy

Basic info:

  • Node.js version: 18
  • jsdom version: 22

Minimal reproduction case

import jsdom from "jsdom";
const { JSDOM } = jsdom;

const dom = new JSDOM(`
  <!doctype html>
  <html>
    <head></head>
    <body>
      <form>
        <input name="one" value="" />
        <input name="two" value="" />
      </form>
    </body>
  </html>
`);

console.log(dom.window.document.forms.length); // 1
console.log(dom.window.document.forms[0].length); // 2

// this should report `HTMLInputElement {}` but doesn't
console.log(dom.window.document.forms[0][0]); // undefined <--- !!!

How does similar code behave in browsers?

Index access on a form object to access its form elements in browsers returns the form's element node found at that index. Attempting the same thing in JSDOM returns undefined.

Relevant portion from the spec

https://html.spec.whatwg.org/multipage/forms.html#htmlformelement

formelement

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    metr upliftA candidate for the METR Uplift experiment

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions