Remove CSS class from element with JavaScript (no jQuery) [duplicate] Remove CSS class from element with JavaScript (no jQuery) [duplicate] javascript javascript

Remove CSS class from element with JavaScript (no jQuery) [duplicate]


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}
<div id='el' class="red"> Test</div><button id='remove'>Remove Class</button>