0

How can I do that? Right now it does increase the number, which it should but removes "tykkäykset"

<span class="amount">3 tykkäykset</span>

var num = parseInt($.trim($('.amount').html()));
$('.amount').html(++num);

I'm a complete novice

2 Answers2

2

I would recommend creating a element for the amount and change the value in there:

<span class="my-amount"><span class="amount">3</span> tykkäykset</span>

var num = parseInt($.trim($('.amount').html()));
$('.amount').html(++num);
Philipp Sander
  • 10,139
  • 6
  • 45
  • 78
  • I would also use `text()` and provide the [radix for `parseInt`](http://stackoverflow.com/a/6611854/11683). – GSerg Feb 01 '17 at 16:12
0

Try this code:

var text = $.trim($('.amount').html());
var res = text.split(" "); 
var num = parseInt(res[0]) + 1;
text = num + " "+ res[1];
$('.amount').html(text);

However, i would also recommend Philipp Sander response.

Mazyad
  • 65
  • 8