name | {String} | The name of the attribute |
value | {Any} [optional] | A value to be set. Most values will be converted to a String before setting. Functions will be evaluted with (previousValue, index) and the return value will be set. |
Value or DollarJS (chainable)
$('img').attr('title')
$('img').attr('title', 'Click Me')
$('img').attr('title', function(previousValue, index){ return 'Click Me'; })
If value is provided, this will set the attribute on each element and return the current set for chaining
If value is not passed, this will return the value of the attribute for the first element in the current set
There is a difference between attr vs prop