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

Cannot set certain element style properties to empty #3372

Closed
yyx990803 opened this issue May 20, 2022 · 1 comment · Fixed by jsdom/cssstyle#162
Closed

Cannot set certain element style properties to empty #3372

yyx990803 opened this issue May 20, 2022 · 1 comment · Fixed by jsdom/cssstyle#162
Labels

Comments

@yyx990803
Copy link

yyx990803 commented May 20, 2022

Basic info:

  • Node.js version: 16.13.2
  • jsdom version: 19.0.0

Minimal reproduction case

This works as expected:

const el = document.createElement('div')
el.style.margin = '10px'
console.log(el.style.margin) // '10px'

el.style.margin = ''
console.log(el.style.margin) // ''

This does NOT:

const el = document.createElement('div')
el.style.marginLeft = '10px'
console.log(el.style.marginLeft) // '10px'

el.style.marginLeft = '20px'
console.log(el.style.marginLeft) // '20px'

el.style.marginLeft = ''
console.log(el.style.marginLeft) // '20px'

Note after setting marginLeft to empty, the value on style is still '20px'.

How does similar code behave in browsers?

You can just paste the code in the browser console to witness the expected behavior: el.style.marginLeft should return empty string.

@yyx990803 yyx990803 changed the title Setting individual element style properties sometimes doesn't Setting individual element style properties sometimes doesn't work May 20, 2022
@yyx990803 yyx990803 changed the title Setting individual element style properties sometimes doesn't work Cannot set certain element style properties to empty May 20, 2022
@sombriks
Copy link

yep it works on browser
Captura de tela de 2022-05-20 02-22-15
but not on jsdom
Captura de tela de 2022-05-20 02-23-02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants