You can do this using .attr( attributeName, function(index, attr) ) :
$("td.myTD").attr("rowspan", function(index, attr){ return parseInt(attr, 10) + 1; });
Here in the above code, a function is used that takes the position of the index of the element in the set and the value of the old attribute as arguments. And then the function returns the new attribute value based on the old attribute. This use of a function to calculate attribute values ββis especially useful when changing the attributes of several elements at the same time.
See the attr (index, attr) documentation for more information.
palas source share