I have a piece of php that outputs divs (depending on how many is in the array) and assigns that div with an id (i.e div_1, div_2) etc
I also set a hidden field with the count of how many divs were outputted (divcount)
So lets say I have 5 divs then the id’s of the div’s will be
- div_1,
- div_2,
- div_3
- etc etc
- and the hidden field (divcount) will be set to 5
If div_2 gets deleted, I set the divcount hidden field to 4.
What I need to do now is rebuild the other div’s id’s to be:
- div_1,
- div_2,
- div_3,
- div_4,
but currently I am left with div_1, div_3, div_4, div_5
I guess I need a loop to loop through each div and assign the id of THAT div the value of the loop
i.e
- div_1 id becomes div_1
- div_3 id becomes div_2
- div_4 id becomes div_3
- div_5 id becomes div_4
Can anyone advise on how to do this?
Thanks in advance!
You can use
eachmethod.Fiddle