Web Development with jQuery®

(Elliott) #1

bapp05.indd 02/17/2015 Page 523


Manipulating Content,


Attributes, and Custom Data


METHOD/PROPERTY DESCRIPTION RETURN
VALUE

AT TRIBUTES

attr(name) Returns the attribute value for the speci-
fi ed attribute from the fi rst element present
in a selection. If no element is present, the
method returns undefined.

String,
Undefi ned

attr(object) Allows you to set attributes via the specifi ca-
tion of key, value pairs. For example:
attr({
id : 'idName',
href : '/example.html',
title : 'Tooltip text.'
});

jQuery

attr(key, value) Allows you to specify an attribute by pro-
viding the name of the attribute in the
key argument and its value in the value
argument.

jQuery

attr(key, function) Sets an attribute’s value depending on the
return value of the callback function that you
specify. The callback function is executed
within the context of each selected ele-
ment, where each selected element can be
accessed within the function via this.

jQuery

E


continues

http://www.it-ebooks.info

Free download pdf