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

InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList' due to space in CSS variable token #13

Open
h1un opened this issue Jan 16, 2025 · 0 comments

Comments

@h1un
Copy link
Contributor

h1un commented Jan 16, 2025

When attempting to use element.classList.add() with a CSS custom property containing a space, the following error occurs:

Unhandled Runtime Error
InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList': The token provided ('[--lexical-indent-base-value: 40px]') contains HTML space characters, which are not valid in tokens.

Possible Solutions:
element.classList.add('[--lexical-indent-base-value: 40px]');

->

  1. Use style.setProperty instead:
    element.style.setProperty('--lexical-indent-base-value', '40px');
  2. Remove the space from the token:
    element.classList.add('[--lexical-indent-base-value:40px]');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant