Using a function to update a value within the data() method of jQuery sets the variable equivalent to the anonymous function, not the return value
<p>I answered this question: <a href="http://stackoverflow.com/questions/16612828/manipulate-custom-values-with-jquery">Manipulate Custom Values with jQuery</a></p>

<p>With this jQuery:</p>

<pre><code>$('img').attr('u', function(i,u) {
    /* i is the index of the current image among all the images returned by the selector,
       u is the current value of that attribute */
    return u.slice(0, -1) + (parseInt(u.replace(/\D/g,''), 10) + 1);
});
</code></pre>

<p><a href="http://stackoverflow.com/a/16612943/82548">Link to answer</a>, <a href="http://jsfiddle.net/davidThomas/xcU84/" rel="nofollow">JS Fiddle demo from that answer</a>.</p>

<p>But then I felt I should show how to do it 'properly,' using the custom <code>data-*</code> attributes allowed under HTML5 (rather than the invalid, albeit functional, custom attributes), so I adapted the HTML to:</p>

<pre><code>&lt;img src="http://placekitten.com/400/500" class="className" click="" id='button4' data-u="button6" data-r="button5" data-l="ele1" data-d="" /&gt;
</code></pre>

<p>(No, I've got no idea what the <code>click</code> attribute's meant to do, or why it's there, so I left it alone.)</p>

<p>And tested the following jQuery:</p>

<pre><code>$('img').data('u', function(i,u) {
    /* i is the index of the current image among all the images returned by the selector,
       u is the current value of that attribute */
    return u.slice(0, -1) + (parseInt(u.replace(/\D/g,''), 10) + 1);
});

$('img').each(function(){
    console.log($(this).data('u'));
});
</code></pre>

<p><a href="http://jsfiddle.net/davidThomas/xcU84/1/" rel="nofollow">JS Fiddle demo</a>.</p>

<p>Now, with the <code>data()</code> method I realise that the attribute wouldn't be updated, which is why I used the <code>console.log()</code> to confirm the updated value, the output, however, is the anonymous function <em>itself</em>, not the value that I expected to be returned <em>from</em> that function. I realise this is unlikely to be a bug, and is probably the expected behaviour, but is there a way to use an anonymous function to update the attributes in the same way as, for example, that used within <code>attr()</code>, <code>text()</code>, etc..?</p>
