Check out example codes for "toggle css class in javascript". It will help you in understanding the concepts better.

Code Example 1

/* var or const followed by its name */.getElementById(/* HTML element ID */);
/* var or const's name */.classList.toggle(/* Name of CSS class */);
// I hope this helps!

Code Example 2

$( "#foo" ).toggleClass( 'className', addOrRemoveOptional );

Code Example 3

var menu = document.querySelector('.menu') // Using a class instead, see note below.
menu.classList.toggle('hidden-phone');

Code Example 4

function myFunction() {
  var element = document.getElementById("myDIV");

    element.classList.toggle("mystyle");
}

Learn ReactJs, React Native from akashmittal.com