Essentially yes, that is what it is doing, the return value of the function is what is used to set the value of the attribute. Here are the
details. Most of the jQuery methods that set a value have that functionality.
Yes, it is similar to just using a specific value to set the attribute, but using the function gives you the ability to do something that might be more complex or be different for each element being affected.
If you want to get a value out of the function you would need to save it in a global variable, but keep in mind that if you do something like:
- var theValue;
- $("img").attr("title", function() {
- theValue = $(this).attr("alt");
- return theValue;
- });
After that is done executing the value of theValue is going to be the last one that was done. If you need them all would need to create an array and add them all to it as you processed them. Is that what you meant?
Dave