I have a number in a span tag. I need to get the value of the number in the span and then increment it inside jQuery. I know how to do this for a text input - can this be done to a span tag?
SPAN tag
<span class="changeNumber"> 33 </span>
jQuery span selector
var commentNumAppend = $(this).closest(".songContainer").find(".changeNumber");
Example -
<span class="changeNumber">33</span>
$('.changeNumber').html(parseInt($('.changeNumber').html(), 10)+1)
You can do something like:
var value = parseInt($(".changeNumber").text(), 10) + 1;
$(".changeNumber").text(value);
JsFiddle Example:
http://jsfiddle.net/stapiagutierrez/WXAvS/1/
References:
parseInt()
text()
This is the most complete answer.
<span class="changeNumber"></span>
var $number = $('.changeNumber');
$number.html((parseInt($number.html(),10) || 0) + 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With