Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getElementsByClassName returns wrong results when given multiple classes #1551

Closed
hombrew opened this issue Sep 24, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@hombrew
Copy link

hombrew commented Sep 24, 2024

To Reproduce

import { Window } from "happy-dom";

const window = new Window();
const document = window.document;

document.body.innerHTML = `
<div class="class1 class2">
  <div class="class2">
    <span>hi</span>
  </div>
</div>`;

const arr1 = Array.from(document.getElementsByClassName("class1 class2"));
console.log(arr1.length); // output: 0 - wrong

Expected behavior
in this case getElementsByClassName should return 1 element as shown here

Device:

  • OS: OSX Sonoma 14.6.1
  • Browser Chrome
  • Version 129.0.6668.58

Additional context
based on the same code, comma separated classes work as expected:

const arr2 = Array.from(document.getElementsByClassName("class1, class2"));
console.log(arr2.length); // output: 1 - ok
@hombrew hombrew added the bug Something isn't working label Sep 24, 2024
capricorn86 added a commit that referenced this issue Dec 30, 2024
…lementsByClassName

* fix: Allow getElementsByClassName to accept a whitespace-separated list

* chore: [#1618] Improves performance for getElemenmtsByClassName space separated list

---------

Co-authored-by: David Ortner <david@ortner.se>
@capricorn86
Copy link
Owner

Thank you for reporting @hombrew! 🙂

Big thanks to @kylehalleman for contributing with a fix ⭐

The fix has been released in v16.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants