I have a dynamically created table that has buttons associated. I would like a simple JavaScript method that would apply to every single button. Right now, it only references the first button created.
<table>
<tbody>
<% @task.subtasks.each do |subtask| %>
<tr>
<td>
<button class="btn btn-default" id="collapseBtn"><span class="glyphicon glyphicon-plus" id="collapseSpan"></button>
</td>
<td> <%= subtask.name %></td>
</tr>
<%end%>
</tbody>
</table>
<script>
$("#collapseBtn").click(function(){
$("#collapseSpan).toggleClass("glyphicon-plus glyphicon-minus");
});
</script>