You’re currently appending the number to the end of the string, this has nothing to do with arithmetic.
Just add the calculated result
foo.setAttribute("item-position", bar+1);
You don’t have to turn it into a string, setAttribute
will do that part.
Or if you want to increase the value in bar
and show it, use the preincrement operator:
foo.setAttribute("item-position", ++bar);
solved The way to increase variable