The event object dispatched when an attribute changes on an element.
Object
Properties
-
attributeName
{String}
The name of the attribute that was changed.
-
oldValue
{String}
The old value of the attribute.
-
target
{HTMLElement}
The attribute that changed.
-
type="attributes"
{String}
Optional
The type is always "attributes" for an attributes event.
-
bubbles=false
{Boolean}
Optional
Attributes events do not bubble.
Use
Listen to an
attributes
event on an element with the base-library's NodeList. For example, with jQuery:Listen to an
attributes
event with can.Control like:Listen to an
attributes
event with can.Component's events object like:With jQuery, in browsers that support MutationObsever you can set attributes direction with
setAttribute
like:To create an
attributes
event in all browsers, you must use the base-library NodeList's attribute methods.For jQuery or Zepto, use
$.fn.attr
For Mootools use Element::set:
For Dojo, use
dojo.setAttr
ordojo.removeAttr
;For YUI use
can.attr.set
like:Asynchronous dispatching
Unlike all other events in CanJS, "attributes" events are dispatched asynchronously. That means that attribute event handlers are not fired until the all current operations are complete. For example:
Ouputs