3 // Can't use `classList.toggle` with the second parameter (force)
4 // Because IE11 does not support it
5 var toggleClass = function(element, class1, force) {
8 // note: svg on IE does not have classList so fallback to class
9 if (element.classList) {
10 if (arguments.length === 3) {
12 element.classList.add(class1);
14 element.classList.remove(class1);
17 result = element.classList.toggle(class1);
19 } else if (element.getAttribute) {
20 var classContent = element.getAttribute('class');
21 var classContentWithoutTargetClass = classContent.replace(
22 new RegExp('(^|\\s)' + class1 + '($|\\s)'),
25 if (force || classContent === classContentWithoutTargetClass) {
26 element.setAttribute('class', classContentWithoutTargetClass + ' ' + class1);
28 element.setAttribute('class', classContentWithoutTargetClass);
35 module.exports = toggleClass;