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

Issue with "HTMLElement.style": IE11 fails unsetting style using null #16828

Closed
vlakoff opened this issue Mar 21, 2022 · 4 comments
Closed

Issue with "HTMLElement.style": IE11 fails unsetting style using null #16828

vlakoff opened this issue Mar 21, 2022 · 4 comments
Labels
data:api 🐇 Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API

Comments

@vlakoff
Copy link
Contributor

vlakoff commented Mar 21, 2022

MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

What information was incorrect, unhelpful, or incomplete?

To remove a given style, it is usually advised to set its property to null, e.g. element.style.color = null

However, it seems to silently fail on IE11, which requires to assign an empty string, e.g. element.style.color = ''

(of course, other browsers support assigning an empty string too)

Specific section or headline?

Yes: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#setting_styles

What did you expect to see?

If confirmed, this IE11 caveat should be documented.

Did you test this? If so, how?

According to this answer on Stack Overlow, and its comments:
https://stackoverflow.com/questions/18691655/remove-style-on-element/33039348#33039348

MDN Content page report details
@vlakoff
Copy link
Contributor Author

vlakoff commented May 11, 2022

I could find a few other notes on Stack Overflow, for instance here and here. I haven't tested it personally yet, but according to the comments, assigning null does nothing on latest IE's and even produces errors on older IE's. Thus this issue may not be specific to IE11, but also impact older IE's.

Also, on the MDN page, we may want to add a reference to an alternative solution: the removeProperty() method (IE9+). It is probably slower than assigning '' to the property, but it might have its use cases, and nevertheless it should be mentioned for the sake of completeness.

@sideshowbarker sideshowbarker transferred this issue from mdn/content Jun 29, 2022
@queengooborg queengooborg added data:api 🐇 Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API needs triage 🔎 and removed help wanted labels Jul 1, 2022
@vlakoff
Copy link
Contributor Author

vlakoff commented Oct 10, 2022

I just successfully reproduced the issue, using Internet Explorer 11 and its "emulation mode" in the developer toolbar.

All offered IE versions have the issue: 5, 7, 8, 9, 10, and even 11. (there is no IE 6, not a typo)

Setting to '' removes the style as expected, whereas setting to null doesn't remove it.
Also, I didn't get any JavaScript error in the console.

@queengooborg
Copy link
Collaborator

I'm closing this issue since the IE data was frozen a few releases back.

@queengooborg queengooborg closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2022
@vlakoff
Copy link
Contributor Author

vlakoff commented Dec 20, 2022

How about adding a short sentence, still?

Something like:

A style declaration is reset by setting it to null or an empty string, e.g., elt.style.color = null. Note that Internet Explorer does nothing if null is used, it works only with an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:api 🐇 Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API
Projects
None yet
Development

No branches or pull requests

4 participants