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

toggleAttribute is not a function #724

Closed
alexbot89 opened this issue Feb 7, 2023 · 1 comment · Fixed by #752
Closed

toggleAttribute is not a function #724

alexbot89 opened this issue Feb 7, 2023 · 1 comment · Fixed by #752
Labels
bug Something isn't working

Comments

@alexbot89
Copy link

Describe the bug
When attempting to access function toggleAttribute after .querySelector, an error is displayed:

container.toggleAttribute('disabled');
          ^

TypeError: container.toggleAttribute is not a function
    at file:///D:/Projects/happ-dom-repro1/index.js:9:11
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v18.12.0

According to MDN, this function should be supported:
https://developer.mozilla.org/en-US/docs/Web/API/Element/toggleAttribute

To Reproduce
Run this code with node index.js after basing it off the basic example:

import { Window } from 'happy-dom';

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

document.body.innerHTML = '<div class="container"></div>';

const container = document.querySelector('.container');
container.toggleAttribute('disabled');

Expected behavior
Attributes should be toggle on/off as expected of the spec from MDN.

Device:

  • OS: Windows 11
@alexbot89 alexbot89 added the bug Something isn't working label Feb 7, 2023
btea added a commit to btea/happy-dom that referenced this issue Feb 14, 2023
capricorn86 added a commit that referenced this issue Feb 14, 2023
@capricorn86
Copy link
Owner

Thanks for reporting @alexbot89! 🙂

Big thanks to @btea for the contribution!

The fix has now been released.

You can read more about it here:
https://github.com/capricorn86/happy-dom/releases/tag/v8.4.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

Successfully merging a pull request may close this issue.

2 participants