Home >Web Front-end >CSS Tutorial >How Can I Remove a CSS Class with JavaScript Without Using jQuery?
Removing CSS Class with JavaScript without jQuery
To eliminate a class on an element in JavaScript, steer clear of jQuery and try out the classList property. Widely supported in modern browsers, it offers a standardized solution:
Code:
ELEMENT.classList.remove("CLASS_NAME");
Example:
const remove = () => { const el = document.querySelector('#el'); el.classList.remove("red"); };
HTML:
<div>
CSS:
.red { background: red }
By implementing classList.remove(), you can effortlessly remove a specified CSS class from an element, enabling dynamic control over the element's appearance without relying on jQuery.
The above is the detailed content of How Can I Remove a CSS Class with JavaScript Without Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!