I have a simple html block like:
<span id='replies'>8</span>
Using jquery I’m trying to add a 1 to the value (8).
var currentValue = $('#replies').text(); var newValue = currentValue + 1; $('replies').text(newValue);
What’s happening is it is appearing like:
81
then
811
not 9, which would be the correct answer. What am I doing wrong?
parseInt() will force it to be type integer, or will be NaN (not a number) if it cannot perform the conversion.
The second paramter (radix) makes sure it is parsed as a decimal number.