Skip to content

data() setters skip all elements when the selection starts with text #5557

Description

@xu91102

Calling a .data() setter on a mixed selection returned by .contents() skips every element when the first node is text.

const $ = load('<div>text<span></span></div>');
const contents = $('div').contents();
contents.data('foo', 'bar');
console.log($('span').data('foo')); // undefined, expected 'bar'

The object-map setter has the same problem. Both setters also return undefined instead of the selection in this case. Existing behavior and tests set data on all elements when the selection starts with an element; the leading text should simply be skipped.

Reproduced against main 0ab9a8e on macOS / Node.js. Baseline attributes tests pass; a public API regression fails. Proposed fix: execute the existing setter iteration before applying the first-element check that is needed for getters. Correct the two setter docstrings which currently describe first-element-only behavior.

Investigated with OpenAI Codex assistance.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions