Jquery number increment to <p> tag -
i trying write variable holds main value of paragraph tag seen here:
<button id="button">random words</button> <p id="inc">0</p> <script> $(document).ready(function(){ $('#button').on("click", function(){ var oldval = $("#inc") $('#inc').text( oldval + 1) }); }); </script>
how turn '#inc' number can + 1 increment?
you can use callback text function accept old text , modify new.
you need parse old value integer incrementing it:
$('#button').on("click", function(){ $('#inc').text(function(i,oldval){ return parseint(oldval,10) + 1 ; }); });
Comments
Post a Comment