How can I use jquery to increment a table cell by 1 each time the button is clicked? -
How can I use jquery to increment a table cell by 1 each time the button is clicked? -
here html:
<table class="mytable" summary="table ages"> <tr> <th>name</th> <th>age</th> </tr> <tr> <td>joe</td> <td id="joesage">35</td> </tr> <tr> <td>becky</td> <td id="beckysage">40</td> </tr> <tr> <td>joey</td> <td id="joeysage">50</td> </tr> </table> <button onclick="add">add</button>
i need cells joesage, beckysage , joeysage each increment 1 each time add together button clicked. can assist me please? give thanks you.
please show have tried or atleast have level of understanding doing. don't deliberately post problem solved world. can see new user. so, have not down-voted post. here's solution time:
<script type="text/javascript"> function add(){ // solution // row want // value, parseint , increment 1 // replace content of row incremented value var joesagetd = document.getelementbyid("joesage"); var newjoesage = parseint(joesagetd.innerhtml) + 1; joesagetd.innerhtml = newjoesage; var beckysagetd = document.getelementbyid("beckysage"); var newbeckysage = parseint(beckysagetd.innerhtml) + 1; beckysagetd.innerhtml = newbeckysage; var joeysagetd = document.getelementbyid("joeysage"); var newjoeysage = parseint(joeysagetd.innerhtml) + 1; joeysagetd.innerhtml = newjoeysage; } </script> <table class="mytable" summary="table ages"> <tr> <th >name</th> <th>age</th> </tr> <tr> <td>joe</td> <td id="joesage">35</td> </tr> <tr> <td>becky</td> <td id="beckysage">40</td> </tr> <tr> <td>joey</td> <td id="joeysage">50</td> </tr> </table> <button onclick="add()">add</button>
jquery table cell increment
Comments
Post a Comment