Delete specific buttons in a list view

Delete specific buttons in a list view

I have a list view that has grouping rows that I created dynamically
The first row in the list view is a grouping row.
I can recognize a grouping row from
<td colspan="6">Block Title: LastTime Chatted</td>
It will always contain 'Block Title'

After a Group row there will be a variable number of rows that have buttons in the first column

<input type="submit" name="BlocksGroupedByBlockName$ctrl4$btnAddContent" value="Add Text" id="BlocksGroupedByBlockName_btnAddContent_4">

The value will always be 'Add Text'

What I want to do is to delete all except the last button in each group.

Note-the Listview ends in a row that has a button-not in a group row. So that button should not be deleted.

How would I do that?

TIA