Reputation: 317
Only one div in my html code has a class of active-tab. I want to remove the active-tab class from the div.
var activeTab = document.querySelector('.active-tab');
activeTab.className.replace("active-tab",'');
The above code does not seem to work. Please explain why.
PS - Please don't give me any jQuery answers.
Upvotes: 1
Views: 48
Reputation: 67207
You have to set the className
,
var activeTab = document.querySelector('.active-tab');
activeTab.className = activeTab.className.replace("active-tab",'');
You are simply getting the result of className
(a string), manipulating it and leaving that string alone. You have to set the modified string back to the className property of that element to accomplish your task.
Upvotes: 5