- Project owner
Eugene Lazutkin
- since
V1.7
This module defines the core Dojo DOM attributes API. This module will eventually be retired and wholly superseded by the dojo/dom-prop <dojo/dom-prop>
module in the future. The standard return variable for this module is domAttr
.
The deprecated legacy features are set in dojo/_base/html <dojo/_base/html>
.
A function that checks if an attribute is present on a DOM node, and returns the truthy value if it is there, and falsy value otherwise.
Argument | Description |
---|---|
node | id or reference of the DOM node to get/set style for |
attr | the attribute property name |
result | truthy, if the attribute is present, falsy otherwise |
Checking to see if a particular node as an attribute.
A function that handles normalized getting of attributes on DOM Nodes and return the value of the requested attribute or null if that attribute does not have a specified or default value.
Argument | Description |
---|---|
node | id or reference to the element to get the attribute on |
attr | the name of the attribute to get |
Getting some values from a node.
A function that handles normalized setting of attributes on DOM Nodes. When passing functions as values, note that they will not be directly assigned to slots on the node, but rather the default behavior will be removed and the new behavior will be added using dojo.connect()
, meaning that event handler properties will be normalized and that some caveats with regards to non-standard behaviors for onsubmit
apply. Namely that you should cancel form submission using event.stop() <dojo/_base/event#dojo-stopevent>
on the passed event object instead of returning a boolean value from the handler itself. It returns the DOM node.
Argument | Description |
---|---|
node | id or reference to the element to set the attribute on |
attr | the name of the attribute to set, or a hash of key-value pairs to set |
value | the value to set for the attribute, if the name is a string |
Here is an example of changing a value of an attribute:
Here is an example of using an object to set multiple attribute values:
Is a function that removes an attribute from a DOM node. It is modeled after DOM's removeAttribute, but unlike the latter it normalizes standard attribute names to smooth over differences between browsers, or to provide convenient aliases, (e.g., className
is aliased to class
).
Argument | Description |
---|---|
node | id or reference to the element to remove the attribute on |
attr | the attribute name |
Here is an example of removing the disabled
attribute from a DOM node:
Is a companion function for domAttr.get <dojo/domAttr#domattr-get>
. Unlike the latter it favors properties falling back on attributes, if a property was not present.
It is useful when you don't care if somebody set an attribute on a node in HTML, or not, but you want to read a default/current value, which is used by a browser. For example, if user didn't specify type
attribute on input
element, it is default value is "text"
. You don't need to know all defaults, or how browser interprets missing attributes exactly, just use domAttr.getNodeProp
.
There is no corresponding setNodeProp
. If you want to set a property value, use straight assignment.
Argument | Description |
---|---|
node | id or reference to the element to get the property on |
attr | the attribute property name |
The following example reads effective values from the input
node.
dojo/dom <dojo/dom>
- Core DOM APIdojo/dom-class <dojo/dom-class>
- Dojo DOM Class APIdojo/dom-prop <dojo/dom-prop>
- DOM Property APIdojo/dom-style <dojo/dom-style>
- DOM Style APIdojo/_base/html <dojo/_base/html>
- Legacy API aliases