If the browser does not support classList toggleClass does not have the same behaviour.
If the toggled class already exists on an element toggleClass will add that same class to the className string, which means the class can never be removed.
This is caused by the internal addClass function not checking for the new class existing in the className string before appending.
I suppose the fix would be something like:
addClass = function (el, c) {
if (!hasClass(el,c) {
el.className = trim(el.className + ' ' + c);
}
}
That would unfortunately make the addClass API call hasClass twice.
However, given that add/removeClass API functions now have the same functionality as their classList equivalents the hasClass checks are now unnecessary and can be removed.
If the browser does not support classList toggleClass does not have the same behaviour.
If the toggled class already exists on an element toggleClass will add that same class to the className string, which means the class can never be removed.
This is caused by the internal addClass function not checking for the new class existing in the className string before appending.
I suppose the fix would be something like:
addClass = function (el, c) { if (!hasClass(el,c) { el.className = trim(el.className + ' ' + c); } }That would unfortunately make the addClass API call hasClass twice.
However, given that add/removeClass API functions now have the same functionality as their classList equivalents the hasClass checks are now unnecessary and can be removed.