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
attributesevent on an element with the base-library's NodeList. For example, with jQuery:Listen to an
attributesevent with can.Control like:Listen to an
attributesevent with can.Component's events object like:With jQuery, in browsers that support MutationObsever you can set attributes direction with
setAttributelike:To create an
attributesevent in all browsers, you must use the base-library NodeList's attribute methods.For jQuery or Zepto, use
$.fn.attrFor Mootools use Element::set:
For Dojo, use
dojo.setAttrordojo.removeAttr;For YUI use
can.attr.setlike: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