<span id="shortfall" style="color:black">$row[shortfall]</span>
How to increase $row[shortfall] to $row[shortfall]+1 with JQuery?
<span id="shortfall" style="color:black">$row[shortfall]</span>
How to increase $row[shortfall] to $row[shortfall]+1 with JQuery?
You need parseInt
to handle strings as numbers.
$("#shortfall").text(parseInt($("#shortfall").text()) + 1);
By the time it gets to the browser, your expression will have been evaluated and turned into a number. To use jQuery you'd simply get the text value of the span, convert it to a number, then replace the text value. You will need to convert the value to a number before doing the addition or it will do string concatenation.
$("#shortfall").each( function() {
$(this).text( Number($(this).text()) + 1 );
});
Updated: I'm using each to show how you would do this using a generic selector that might accept a collection of inputs. In your case, if you know it matches exactly one element, you might optimize it at the risk of having to rewrite it if you wanted the code to apply to multiple elements.
var span = $("#shortfall");
span.text( Number( span.text() ) + 1 );
Updated: need to use text() (or html()) since the element is a SPAN, not an input.