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
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
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);
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.