Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 qunit
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.markdown
Octocat-spinner-32 changelog
Octocat-spinner-32 jquery.classlist.js
Octocat-spinner-32 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.