-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_class.js
More file actions
30 lines (27 loc) · 985 Bytes
/
Copy pathtoggle_class.js
File metadata and controls
30 lines (27 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//Ths class requires an array of div elements with a set className
//We will use the index number in the array to set them to active
class activeClassToggle {
constructor(id,classes,classname) {
this.classes = document.getElementById(id).getElementsByClassName(classes);
this.classname = classname;
}
//returns the possition in the array of the current active element
activeCol() {
for (let i=0; i < this.classes.length; i++) {
if (this.classes[i].classList.contains(this.classname)) {
return i;
}
}
}
//we will remove the old active and set the new
setActive(activeOld,activeNew) {
for (let i=0; i < this.classes.length; i++) {
if (activeOld == i) {
this.classes[i].classList.remove(this.classname);
}
if (activeNew == i) {
this.classes[i].classList.add(this.classname);
}
}
}
}