-1

This's my codes:

var following_tags = $('.follow-tags-start').attr("data-following-tags");

$('.follow-tags-start').attr('data-following-tags', following_tags+1);

the issue that if the count of data-following-tags="0" after do the action the count add 1 with the exists count so each time i do the action it's add 1 with 0. data-following-tags="01111"

Dij
  • 9,761
  • 4
  • 18
  • 35
John Dors
  • 9
  • 2

2 Answers2

0

you can use parseInt() (assuming these are integer numbers) to convert data attribute to integer, then you can add 1. something like this:

var following_tags = parseInt($('.follow-tags-start').attr("data-following-tags"));

$('.follow-tags-start').attr('data-following-tags', following_tags+1);
Dij
  • 9,761
  • 4
  • 18
  • 35
0

You can just use a callback, and coerce the value to a number

$('.follow-tags-start').attr("data-following-tags", function(attr) {
    return (+attr) + 1
});
adeneo
  • 312,895
  • 29
  • 395
  • 388