Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
JavaScript
Tree: 42fa5c64aa

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
qunit
test
.gitignore
README.markdown
changelog
jquery.classlist.js
jquery.support.stub.js

README.markdown

.classlist()

Provides an interface for handling class attributes as arrays of className strings:

Performance Evidence

Array of Classes Survey

API

.classlist()

  • .classlist( )
  • .classlist( ["set", "this", "array", "of", "classes"] )

Examples

Elements may have more than one class assigned to them. In HTML, this is represented by separating the class names with a space:

<div id="mydiv" class="foo bar baz quux"></div>

The .classlist() method will return an array of classes on first element of the matched elements:

.classlist()

Get an array of all classes on an element $('#mydiv').classlist() > [ "foo", "bar", "baz", "quux" ]

The .classlist( [ "foo", "bar", "baz" ] ) method will take an array of class strings and apply them to all the elements in the matched set:

.classlist( [ "foo", "bar", "baz" ] )

Set classes on elements with an array of strings, returns the matched set $('#mydiv').classlist([ "foo", "bar", "baz", "quux" ]) > [ div#mydiv ]
Something went wrong with that request. Please try again.