<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml-stylesheet type='text/xsl' href='docs.xsl'?>
<docs>
<method cat='DOM/Attributes' type='Object' short='Access a property on the first matched element.' name='attr'>
<desc>Access a property on the first matched element.
This method makes it easy to retrieve a property value
from the first matched element.

If the element does not have an attribute with such a
name, undefined is returned.</desc>
<params type='String' name='name'>
<desc>The name of the property to access.</desc>
</params>
<examples>
<desc>Returns the src attribute from the first image in the document.</desc>
<before>&lt;img src="test.jpg"/&gt;</before>
<code>$("img").attr("src");</code>
<result>test.jpg</result>
</examples>
</method><method cat='DOM/Attributes' type='jQuery' short='Set a key/value object as properties to all matched elements.' name='attr'>
<desc>Set a key/value object as properties to all matched elements.

This serves as the best way to set a large number of properties
on all matched elements.</desc>
<params type='Map' name='properties'>
<desc>Key/value pairs to set as object properties.</desc>
</params>
<examples>
<desc>Sets src and alt attributes to all images.</desc>
<before>&lt;img/&gt;</before>
<code>$("img").attr({ src: "test.jpg", alt: "Test Image" });</code>
<result>&lt;img src="test.jpg" alt="Test Image"/&gt;</result>
</examples>
</method><method cat='DOM/Attributes' type='jQuery' short='Set a single property to a value, on all matched elements.' name='attr'>
<desc>Set a single property to a value, on all matched elements.

Note that you can't set the name property of input elements in IE.
Use $(html) or .append(html) or .html(html) to create elements
on the fly including the name property.</desc>
<params type='String' name='key'>
<desc>The name of the property to set.</desc>
</params>
<params type='Object' name='value'>
<desc>The value to set the property to.</desc>
</params>
<examples>
<desc>Sets src attribute to all images.</desc>
<before>&lt;img/&gt;</before>
<code>$("img").attr("src","test.jpg");</code>
<result>&lt;img src="test.jpg"/&gt;</result>
</examples>
</method><method cat='DOM/Attributes' type='jQuery' short='Set a single property to a computed value, on all matched elements.' name='attr'>
<desc>Set a single property to a computed value, on all matched elements.

Instead of supplying a string value as described
[[DOM/Attributes#attr.28_key.2C_value_.29|above]],
a function is provided that computes the value.</desc>
<params type='String' name='key'>
<desc>The name of the property to set.</desc>
</params>
<params type='Function' name='value'>
<desc>A function returning the value to set. Scope: Current element, argument: Index of current element</desc>
</params>
<examples>
<desc>Sets title attribute from src attribute.</desc>
<before>&lt;img src="test.jpg" /&gt;</before>
<code>$("img").attr("title", function() { return this.src });</code>
<result>&lt;img src="test.jpg" title="test.jpg" /&gt;</result>
</examples>
<examples>
<desc>Enumerate title attribute.</desc>
<before>&lt;img title="pic" /&gt;&lt;img title="pic" /&gt;&lt;img title="pic" /&gt;</before>
<code>$("img").attr("title", function(index) { return this.title + (i + 1); });</code>
<result>&lt;img title="pic1" /&gt;&lt;img title="pic2" /&gt;&lt;img title="pic3" /&gt;</result>
</examples>
</method></docs>
