The right and standard way to do it is using classList. It is now widely supported in the latest version of most modern browsers:
ELEMENT.classList.remove(“CLASS_NAME”);
remove.onclick = () => {
const el = document.querySelector(‘#el’);
if (el.classList.contains(“red”)) {
el.classList.remove(“red”);
}
}
.red {
background: red
}
Documentation: https://developer.mozilla.org/en/DOM/element.classList
document.getElementById(“MyID”).className =
document.getElementById(“MyID”).className.replace(/bMyClassb/,”);
where MyID is the ID of the element and MyClass is the name of the class you wish to remove.
UPDATE:
To support class names containing dash character, such as “My-Class”, use
document.getElementById(“MyID”).className =
document.getElementById(“MyID”).className
.replace(new RegExp(‘(?:^|\s)’+ ‘My-Class’ + ‘(?:\s|$)’), ‘ ‘);