Somewhat inspired by the original version of Tomalak's answer, you can use the callback-based .text version to change the value in a single jQuery call:
$ticket.text(function(i, t) { return parseInt(t, 10) + 1; });
For those of you who tried to use ++ , it will not work for two reasons:
- You can use
++ only for variables, not for the return value of a function - Even then, in postfix mode, it would return the old value, not the added value
source share