0

I can't make this script to run in safari 9 and Internet Explorer, can anyone locate where the ploblem is? it work perfect in any other browser. Thanks!

https://codepen.io/joaquinlarag/pen/mdyPRyV

const app = (() => {
let body;
let menu;
let menuItems;

const init = () => {
    body = document.querySelector("body");
    menu = document.querySelector(".menu-icon");
    menuItems = document.querySelectorAll(".nav__list-item");

    applyListeners();
};

const applyListeners = () => {
    menu.addEventListener("click", () => toggleClass(body, "nav-active"));
};

const toggleClass = (element, stringClass) => {
    if (element.classList.contains(stringClass))
        element.classList.remove(stringClass);
    else element.classList.add(stringClass);
};

init();
})();
  • IE9 does not support arrow functions. Use normal functions instead for IE support. – Taplar Jan 24 '20 at 19:15
  • As already suggested in the referenced thread that IE does not support Arrow functions. I suggest you use Babel.js to convert your ES6 code to ES5 code which is supported in the IE browser. Then after your code will work in the IE browser. Ref: https://babeljs.io/ – Deepak-MSFT Jan 27 '20 at 01:50
  • Yes! it work with Babel. Just went to Babel website in "Try it out" link, pasted the codes in the left box and copied the right box code that is transpiled to the earlier version of JavaScript. And works perfect! – Joaquín Lara Gómez Jan 28 '20 at 12:21

0 Answers0