javascript - Change numberic value in td with jquery -
how can increase numeric values in <td>
element using jquery? tried following no luck. have button id="#increasenum", , trying change td cell value click.
html:
<table> <tr> <td id="num">1</td> <td id="num">5</td> <td id="num">10</td> </tr> </table>
js:
$(document).ready(function() { $("#increasenum").click(function() { $("#num").html(number(("#num").innertext) + 1); }); });
this makes first <td>
value disappear. suggestions?
try :remove duplicate ids , use class instead. iterate each num increment value shown below
html:
<table> <tr> <td class="num">1</td> <td class="num">5</td> <td class="num">10</td> </tr> </table>
jquery :
$(document).ready(function () { $("#increasenum").click(function () { $(".num").each(function(){ $(this).html(parseint($(this).html())+1); }); }); });