Skip to content

Instantly share code, notes, and snippets.

View linuxguist's full-sized avatar

Nathan S.R. linuxguist

View GitHub Profile
@egeorjon
egeorjon / add_remove_class_with_js.md
Last active October 13, 2023 23:06
Add or Remove css class with Javascript

From: StackOverflow

To change all classes for an element:

document.getElementById("MyElement").className = "MyClass";

To add an additional class to an element:

document.getElementById("MyElement").className += " MyClass";

To remove a class from an element: