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

Element.classList.toggle #57

Open
mad-bizarre opened this issue Apr 25, 2019 · 1 comment
Open

Element.classList.toggle #57

mad-bizarre opened this issue Apr 25, 2019 · 1 comment

Comments

@mad-bizarre
Copy link

Hi, there is a bug in Element.classList.toggle.

First:
https://github.com/msn0/mdn-polyfills/blob/master/src/Element.prototype.classList/classList.js#L157 - this.remove(oldToken), there is no variable oldToken in this function, this is copy-paste from next method DOMTokenListProto.replace, there must be a "val" variable from arguments.

Second:
I replaced this.remove(oldToken) with this.remove(val) but this code is not work in Android 4.2
browser\webview (but it works in Chrome, for example), because expression "this.value" in Android 4.2 returns undefined, so className always added, but never removed.

I tried to submit bug into MDN documentation, but got: Sorry, entering a bug into the product Developer Documentation has been disabled.

Simple implementation in russian version of doc works, but not consider the second argument of "toggle" method https://developer.mozilla.org/ru/docs/Web/API/Element/classList

@ccchapman
Copy link

ccchapman commented Feb 9, 2021

I am also experiencing a problem with Element.classList.toggle's polyfill not working. The second argument, force, is ignored on IE 11. It seems like the polyfill may not be applied in this situation.

This can also be reproduce by grabbing the most up-to-date polyfill snippet from MDN and running a basic example. In this case, you'd expect the element to remain red.

<style>
  .red {
    background: red;
  }
</style>

<div class="red">
  Red
</div>

<script>
  /**
   * [...]
   * Polyfill from https://developer.mozilla.org/en-US/docs/Web/API/Element/classList#polyfill
   */
  document.querySelector(".red").classList.toggle("red", true);
</script>

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

2 participants