robert
robert

Reputation: 27

generate propriet non repeating ids

On my site a user can generate as many select fields as he needs. Each one is placed into li tag. When each tag is added, page count how many tags of that type are on the page and that number plus always repeating string is given as an id of that element. Problem occurs when user delete some of these tags. Page will then start giving already existing ids. What is the best way to generate ids for this kind of page?

example:

<li id="0_li_text">
<li id="1_li_text"> <-- delete
<li id="2_li_text">

<li id="0_li_text">
<li id="2_li_text">
<li id="2_li_text"> <-- this one will be generated

Upvotes: 2

Views: 68

Answers (1)

Mauro Cifuentes
Mauro Cifuentes

Reputation: 76

You may generate an unique ID, by creating a variable, and increments on each li added.

Upvotes: 1

Related Questions