Skip to content

Instantly share code, notes, and snippets.

@Siyanda
Created November 18, 2015 20:35
Show Gist options
  • Select an option

  • Save Siyanda/08230f1b5c9500a7f1bc to your computer and use it in GitHub Desktop.

Select an option

Save Siyanda/08230f1b5c9500a7f1bc to your computer and use it in GitHub Desktop.
// adds class "foo" to el
el.classList.add("foo");
// removes class "bar" from el
el.classList.remove("bar");
// toggles the class "foo"
el.classList.toggle("foo");
// outputs "true" to console if el contains "foo", "false" if not
console.log( el.classList.contains("foo") );
// add multiple classes to el
el.classList.add( "foo", "bar" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment