I need to compute new and edit both the ‘x’ and ‘y’ attributes of an SVG element (rect) using a single jQuery call.
Now I know you can do this:
var incBy = 20;
$('#test').attr('x', function(i, val) {
return parseInt(val) + incBy;
});
which is fine for computing and editing single attributes, but how can I edit multiple attributes in this way?
If you factor it out, you can also do it in one line:
Or abstract it more and pass into a separate function the attributes you want to apply this to
It depends on how far you want to go. You could include the function to be called in the parameters, and the selection criteria too.