2
I have a problem that for many are simple, I have a code that takes the value of a input
of the kind hidden
and when I pick up this amount, I add +1, ie if the value is 3 it add +1 and have to stay 4:
var total = $("#total").attr('value') + 1;
He would have to stay 4 and alter the value
from the input to 4:
$("#total").val(total);
only he returns to me Current Value + 1 that is to say, 31, 41 as if it were string.
That seems like a trick to me, like using
"" + 1
to convert int to string.– Luis Henrique
It’s different, it’s another operator. It’s not sum, it’s the
+
unary that serves precisely to force the conversion (see the link in the reply).– bfavaretto
Cool, I didn’t know you could do it like that. + 1
– André Ribeiro
@Andréribeiro +1 or
+"1"
? ;)– bfavaretto
@bfavaretto Boa :D
– André Ribeiro