jQuery increment value of tag

后端 未结 7 800
小鲜肉
小鲜肉 2020-12-31 04:12

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

7条回答
  •  粉色の甜心
    2020-12-31 04:26

    You can do something like:

    var value = parseInt($(".changeNumber").text(), 10) + 1;
    $(".changeNumber").text(value);
    

    JsFiddle Example:

    http://jsfiddle.net/stapiagutierrez/WXAvS/1/

    References:

    1. parseInt()
    2. text()

提交回复
热议问题