See the dojo/dom-attr reference documentation for more information.
get
(node,name)
Defined by dojo/dom-attr
Gets an attribute on an HTML element.
Handles normalized getting of attributes on DOM Nodes.
Parameter | Type | Description |
---|---|---|
node | DOMNode | String |
id or reference to the element to get the attribute on |
name | String |
the name of the attribute to get. |
Returns: any | undefined | null
the value of the requested attribute or null if that attribute does not have a specified or default value;
// get the current value of the "foo" attribute on a node
require(["dojo/dom-attr", "dojo/dom"], function(domAttr, dom){
domAttr.get(dom.byId("nodeId"), "foo");
// or we can just pass the id:
domAttr.get("nodeId", "foo");
});
getNodeProp
(node,name)
Defined by dojo/dom-attr
Returns an effective value of a property or an attribute.
Parameter | Type | Description |
---|---|---|
node | DOMNode | String |
id or reference to the element to remove the attribute from |
name | String |
the name of the attribute |
Returns: any
the value of the attribute
has
(node,name)
Defined by dojo/dom-attr
Returns true if the requested attribute is specified on the given element, and false otherwise.
Parameter | Type | Description |
---|---|---|
node | DOMNode | String |
id or reference to the element to check |
name | String |
the name of the attribute |
Returns: Boolean | contentWindow.document isn't accessible within IE7/8
true if the requested attribute is specified on the given element, and false otherwise
remove
(node,name)
Defined by dojo/dom-attr
Removes an attribute from an HTML element.
Parameter | Type | Description |
---|---|---|
node | DOMNode | String |
id or reference to the element to remove the attribute from |
name | String |
the name of the attribute to remove |
set
(node,name,value)
Defined by dojo/dom-attr
Sets an attribute on an HTML element.
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 dojo.stopEvent()
on the passed event object instead of returning a boolean value from the handler itself.
Parameter | Type | Description |
---|---|---|
node | DOMNode | String |
id or reference to the element to set the attribute on |
name | String | Object |
the name of the attribute to set, or a hash of key-value pairs to set. |
value | String | Optional
the value to set for the attribute, if the name is a string. |
Returns: any | undefined
the DOM node
// use attr() to set the tab index
require(["dojo/dom-attr"], function(domAttr){
domAttr.set("nodeId", "tabIndex", 3);
});
Set multiple values at once, including event handlers:
require(["dojo/dom-attr"],
function(domAttr){
domAttr.set("formId", {
"foo": "bar",
"tabIndex": -1,
"method": "POST"
}
});
© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/dom-attr.html