can.addClass

  • function
 

Add a class to elements.

can.addClass(nodeList, className)

Parameters

  1. nodeList {NodeList}

    The list of HTML elements to add the class to.

  2. className {String}

    The class to add.

can.addClass( nodelist, className ) adds the specified class(es) to nodelist's HTMLElements. It does NOT replace any existing class(es) already defined.

// Before
<div id="foo" class="monkey" />

can.addClass(can.$("#foo"),"bar")

// After
<div id="foo" class="monkey bar" />

You can also pass multiple class(es) and it will add them to the existing set also.

// Before
<div id="foo" class="monkey" />

can.addClass(can.$("#foo"),"bar man")

// After
<div id="foo" class="monkey bar man" />

This works similarly to jQuery.fn.addClass.