tags:

views:

32

answers:

2

Hey guys quick question. I have a div that gets assigned a number to its id that is taken from the database on page load. I am trying to use jquery to add 1 to that number but for example if the number was 70 to begin with it just becomes 701. Anyone know what I am doing wrong?

echo "<div class=\"total\" id=\"$total\">$total</div>";

var total=$(".total").attr("id");

var newtotal=total+1;
$('.total').html(newtotal);
+4  A: 
   var newtotal=parseInt(total)+1;

Use parseInt to convert the String into an integer.

Vincent Ramdhanie
thanks appreciate it
Scarface
+2  A: 

You need to use parseInt()

echo "<div class=\"total\" id=\"$total\">$total</div>";

var total = parseInt($(".total").attr("id"));

var newtotal=total+1;
$('.total').html(newtotal);
macek
thanks man, appreciate it
Scarface