Using jQuery, I would like to extract the number from <span>and use it to calculate the new value.
<div class="post-100" data-postid="100">
<span class="score">3</span>
</div>
I have a general idea, but I cannot figure out how to refer to an existing range value:
if (response.newvoteid == null)
{
$(".post-" + $(this).data("postid") + " .score").text(
parseInt( **EXISTING VALUE + 1 OR -1**));
}
Update: Now I use the following, which cannot calculate the new value, but just adds the number to the text. For example, <span class="score">3</span>it becomes<span class="score">31</span>
var number = $(".post-" + $(this).data("postId") + " .score").text();
$(".post-" + $(this).data("postId") + " .score").text(number + 1);
source
share