When changing an attr value is it best to use a function

Hi,

When I change the attr value should i be doing

$( “#greatphoto” ).attr( “title”, function( i, val ) { return val + " - photo by Kelly Clark";});

rather than

$( “#greatphoto” ).attr( “title”, “$( ‘#greatphoto’ ).attr( ‘title’)+ - photo by Kelly Clark”);

or does it not make much difference?

as you have written it, yes. the second line inserts the string $( '#greatphoto' ).attr( 'title')+ - photo by Kelly Clark (as you’ve quoted it all). but even without the quote issue it’s better to not fetch the element(s) you’re working on a second time (DOM access is costly, no matter which framework you use).

great, thanks