Javacript code to add and remove class in HTML
Here,is a js code to add and remove certain class from a group of tags,or elements containing certain class or id .In this code,the classname is added to the element when it is clicked and removed from the past element .
const name=document.querySelectorAll('.className_of_html');
function tableActive(){
name.forEach((item)=>
item.classList.remove('Class_Name_To_Be_Added'));
this.classList.add('Class_Name_To_Be_Added');
}
name.forEach((item) =>
item.addEventListener('click',tableActive));
}
0 Comments