javascript - Toggle code not working in IE11 -
here code class called toggle, toggles multiple components in site. html has data attribute on called data-expand-content, , css set when data-expand-content true, display: block or whatever content. , js toggles data attribute on click. works fine on browsers except ie11, please me figure out wrong?
thanks!
here's js
class toggle { constructor(control, el) { const togglelink = document.queryselector('.primary-nav__toggle-link'); control = document.queryselector(control); el = document.queryselector(el); if(el) { control.addeventlistener('click', function(e) { if(el.dataset.expandcontent == "false") { el.dataset.expandcontent = "true" if(e.target == document.queryselector('.primary-nav__toggle-icon')) { document.queryselector('.primary-nav__toggle-icon').setattribute('src', '../assets/close-menu.svg'); } } else { el.dataset.expandcontent = "false"; if(e.target == document.queryselector('.primary-nav__toggle-icon')) { document.queryselector('.primary-nav__toggle-icon').setattribute('src', '../assets/burger-menu.svg'); } } }) } } } // new instances of class passed control , element gets toggled const menu = new toggle('.primary-nav__toggle-link', '#primary-nav'); const bannerel = new toggle('.banner', '.banner');
Comments
Post a Comment