ClassList
ClassList - this method can add new classname to opened tag and its keys these.
1.Add => this key will add new classname
menu.classList.add('bg-success');
console.log(menu.classList);
throught this key we can add more classnames in once like so
menu.classList.add('bg-success','gold','red');
console.log(menu.classList);
2.Remove => this key remove classname more then once
menu.classList.remove('gold','red');
console.log(menu.classList);
3.Contains => this key search classname which we type in and it response us boolean (true/false);
menu.classList.contains('bg-success');
console.log(menu.classLIst);
4.Toggle => This key if there is classname which we type the same it removed, otherwise it adds our classname like newone.
menu.classList.toggle('orange');
console.log(menu.classList);
then if we call this classname again "orange" via toggle key , it remove in this time
menu.classList.toggle('orange');
console.log(menu.classList);
Top comments (0)