dojo.NodeList.attr

Available:since V1.2

A getter and setter for DOM attributes, events and CSS styles adapted to work with node lists.

Introduction

NodeList.attr adapts dojo.attr for use with node lists by applying it to every node in the list.

See dojo.attr for more details.

Usage

1
dojo.query(sel).attr(attr, value);
attr
the attribute property name or an object with key/value pairs suitable for setting each property.
value
If passed, sets value on the node for an attribute, handling cross-browser concerns.

Examples

Setting different node attributes

The following example will set several attributes such as the value and disabled.

<script type="text/javascript">
  function enable(){
    dojo.query("input").attr("disabled", false);
  }
  function disableAndSet(){
    dojo.query("input").attr({
      disabled: true,
      value:    "cool, eh?"
    });
  }
</script>
<p><input name="one"></p>
<p><input name="two"></p>
<p><input name="three"></p>
<p><button onclick="enable();">Enable</button></p>
<p><button onclick="disableAndSet();">Disable &amp; Set</button></p>
Error in the documentation? Can’t find what you are looking for? Let us know!