Tuesday 5 November 2013

simple jquery increment decrement on click

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    var newf = parseFloat($(inc).val())+1;
$(inc).val(newf);
  });

  $("b").click(function(){
    var newm = parseFloat($(inc).val())-1;
$(inc).val(newm);
  });



});
</script>
</head>
<body>
<p>If you click on me, I will add 1.</p>
<b>If you click on me, will reduce 1 </b>



<input type="text" value="1" id ="inc" name="num"/>
</body>
</html>

2 comments: