Skip to content

Instantly share code, notes, and snippets.

@dtulig
Created November 8, 2011 05:10
Show Gist options
  • Save dtulig/1347059 to your computer and use it in GitHub Desktop.
Save dtulig/1347059 to your computer and use it in GitHub Desktop.
>>> var clNode = document.getElementById('clExample');
>>> clNode.classList
// ['red', 'green', 'bold']
>>> clNode.classList.length
3
>>> clNode.classList.remove('bold')
// Now the classList is ['red', 'green']
>>> clNode.classList.add('emph')
// Now the classList is ['red', 'green', 'emph']
>>> clNode.classList.item(0)
red // classList.item takes an index.
>>> clNode.classList.contains('green')
true
>>> clNode.classList.toggle('green')
// Now the classList is ['red', 'emph']
>>> clNode.classList.toggle('green')
// Now the classList is ['red', 'green', 'emph']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment