javascript - How to compare a list of classes against other classes in html? -


i save list of classes attached element click this:

function oneachfeature(feature, layer) {     layer.on({         click: panelshow     }); }  function panelshow(e) {     $("path").removeclass("active");     this.getelement().classlist.add("active");     function staticclasslistcopy(element) {        var dummy = document.createelement('div');        dummy.classname = element.classname;        return dummy.classlist;     } } 

i have list of buttons classes this:

<button class="1600 1500"></button> <button class="1600 1300 1200"></button> <button class="1300 1200 1700 1800"></button>     <button class="1300 1200 1100 1900"></button> 

now need compare if in saved list there class matches classes on buttons , if so, add .active class matching buttons.

jquery has toggleclass feature, , sounds trying do.

$('button').toggleclass('active'); 

so, if class exists on button remove otherwise add it.

you this:

var list = ['.1600', '.1800'];  $('button').filter(list.join(',')).addclass('active'); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -