javascript - How to remove all classes except the one you clicked? -
this functions starts when click on link. needs remove '.is-active' classes on elements attribute [data-route]. , add class '.is-active' on [data-route] element connected link clicked on.
toggle: function(section){ var sections = document.queryselectorall('[data-route]'); (i = 0; < sections.length; i++){ document.queryselector('[data-route]').classlist.remove('is-active'); } document.queryselector(section).classlist.add('is-active'); }
but doesn't work. doesn't remove classes?
see example: http://jordypouw.github.io/myfed2/deeltoets1/index.html
p.s. has in vanilla javascript.
toggle: function(section){ var sections = document.queryselectorall('[data-route]'); (i = 0; < sections.length; i++){ sections[i].classlist.remove('is-active'); // queryselectorall return array of dom elements, u can access them directly. } // suppose in case ' section ' variable clicked element : section.classlist.add('is-active') // if not have store dom element event, , add class here. }
Comments
Post a Comment