Skip to content

rwaldron/jquery-classlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.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 ]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published