The website I am working on needs to have dynamic labels, for example:
If the webpage is listing the authors of a particular book (with more than one author) it would look like this:
Author 1: Nikola Tesla [Remove]
Author 2: Elon Musk [Remove]
Author 3: Alan Turing [Remove]
(note that [Remove]in this case is a button that removes the particular person as a author.)
My problem is this, let's say I removed Elon Musk as an author the label for Turing should now change to reflect that (would become Author 2).
I've tried a couple different things using client side JavaScript (as the solution needs to work without refreshing the page or any postbacks) but I couldn't get close to a working solution myself, my logic seems to be off or limited by my lack of experiance in web dev.. I haven't done much Web Dev at all so I'm really learning as I'm going. The solution would also need to work in the case of the user adding a new author to the book.
Edit: The authors are NOT stored in a table but rather just listed using labels. This (due to things out of my control) cannot be changed.
Edit 2: Here is the code I believe is relevant let me know if anything else is needed.
<div ID='dvAuthor" + i.ToString + "' class='form-group'><div class='col-sm-4 control-label'>
An added twist is that that is on the server side and it replaces a placeholder when the author is added (this means when an author is added that page does refresh -- this is fine, but removing should not require the same). Even more fun is that we're not using JQuery!
The i.ToString is just an integer that is added so that the author's ID is numbered, ex dvAuthor0 and so on.
Edit 3: Reply to @Basic
Okay that clears things up a bit. The div for the author's label is coming from the server (i.e. each time an author is added the page refreshes and the client now has the newly added author presented to them.) So I guess my question is, how would I loop through the div's on the client, or even better could I loop through each author's div and just grab their IDs if I don't know exactly how many authors are on the page? Would it be something like this while(hasNextAuthor) {add author ID to array} Sorry for all the questions, I'm really new to Web Dev stuff, I am trying my best.
Also, I don't need to worry about removing the authors from the webpage, I have a function that does that already (both in the client side and on the server). The numbering is the only thing that needs to be done and it really is only cosmetic, the current numbering system works okay but does not dynamically change the numbering as the user removes authors, but rather waits until the user selects save and then reloads the page with correct numbering.
Edit 4: I think I have a way I can get this done, I just have one hang up... How can I get the number of authors on the webpage from the client side? Is their a way in JavaScript where I can loop through and see how many divs are created for the webpage?