If in doubt, you can also do this on one line:
$('#test').attr('x', myFunction).attr('y', myFunction); function myFunction(i, val) { return parseInt(val) + incBy; }
Or abstract it more and pass the attributes you want to apply to a separate function
process('x', 'y'); function process() { for (var i = 0; i < process.arguments.length; i++) $('test').attr(process.arguments[i]), myfunction); function myFunction(i, val) { return parseInt(val) + incBy; } }
It depends on how far you want to go. You can enable the function that will be called in the parameters, and selection criteria.
source share