1document.getElementById('myButton').onclick = function() {
2 this.classList.toggle('active');
3}
1/* var or const followed by its name */.getElementById(/* HTML element ID */);
2/* var or const's name */.classList.toggle(/* Name of CSS class */);
3// I hope this helps!
1document.getElementById('myButton').onclick = function() {
2
3 var className = ' ' + myButton.className + ' ';
4
5 if ( ~className.indexOf(' active ') ) {
6 this.className = className.replace(' active ', ' ');
7 } else {
8 this.className += ' active';
9 }
10}