John Dors John Dors - 2 years ago 98
Javascript Question

Add +1 for data attributes not working

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

Dij Dij
Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download