Thursday, September 29, 2011

attr(String)

attr(String name) returns Object

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.


Example:

Returns the src attribute from the first image in the document.
$("img").attr("src");
HTML:
<img src="test.jpg"/>
Result:
test.jpg

No comments:

Post a Comment