Pretty sure this decides what you are looking for:
HTML:
<table> <tr><td><button class="editbtn">edit</button></td></tr> <tr><td><button class="editbtn">edit</button></td></tr> <tr><td><button class="editbtn">edit</button></td></tr> <tr><td><button class="editbtn">edit</button></td></tr> </table>
Javascript (using jQuery):
$(document).ready(function(){ $('.editbtn').click(function(){ $(this).html($(this).html() == 'edit' ? 'modify' : 'edit'); }); });
Edit:
Apparently, I should have looked at your sample code first;)
You need to change (at least) the ID attribute of each element. The identifier is a unique identifier for each element on the page, which means that if you have several elements with the same identifier, you will get conflicts.
Using classes, you can apply the same logic to multiple elements without any conflict.
JSFiddle example
Demian brecht
source share