jquery Doing Simple Math? -


i have little div this:

<div id="counter">2</div> 

i'd use jquery either subtract or add let 1, resulting in 3 or 1...

is there way in jquery this? convert string int maybe?

$('#counter').text(function(i,txt) { return parseint(txt, 10) + 1; }); 

example addition: http://jsfiddle.net/2ubmy/

example subtraction: http://jsfiddle.net/2ubmy/1/

to add check negative, this:

$('#counter').text(function(i,txt) {     var result = parseint(txt, 10) - 1;     return (result > 0) ? result : 0;  }); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -