How to save a list of classes using javascript to compare them against other classes later? -
i have series of polygons :
<svg> <path class="_1600 _1500 _1400 leaflet"></path> <path class="_1300 _1700 _1900 leaflet"></path> <path class="_1600 _1400 _1800 leaflet"></path> </svg>
and buttons:
<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>
i need assign class on click , how , works fine:
on click:
this.getelement().classlist.add("active");
now polygons become:
<svg> <path class="_1600 _1500 _1400 leaflet"></path> <path class="active _1300 _1700 _1900 leaflet"></path> <path class="_1600 _1400 _1800 leaflet"></path> </svg>
how can save list of classes of clicked element (to have added .active
after click)? save them can later comprare list match list of classes , if match, attach .active
class matching elements.
i must use:
function oneachfeature(feature, layer) { layer.on({ click: panelshow }); } function panelshow(e) { $("path").removeclass("active"); this.getelement().classlist.add('active'); }
you can use classname
space-separated string containing classes.
this.getelement().classname;
if want have more fancy, static classlist
copy, can create dummy element:
function staticclasslistcopy(element) { var dummy = document.createelement('div'); dummy.classname = element.classname; // import classes return dummy.classlist; }
this object array-like, can iterate desired comparisons.
Comments
Post a Comment