Simple way to make sure you are assigning unique IDs to a series of elements.
1 2 3 4 5 6 7 8 9 10 |
var seedNum = 1; function uniqueID(myKey, seedNum){ var key = myKey + seedNum; if (document.getElementById(key) != null){ return uniqueID(myKey, ++seedNum); } else{ return key; } } |
1 |
uniqueID('state-',seedNum); |
If you want to do IETF RFC-4122 compliant Universally Unique Identifiers (UUID), checkout Pure UUID.
Seems to be all about unique IDs this week ;)
I am a full-stack developer. My expertise include:
I love programming, design and know my way around server architecture as well. I would never feel complete, with one of these missing.
I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest.
Apart from that, I am a peace loving guy who tries to have people around him that think the same. I truly believe in the principle: “If you help someone, someone will help you, when you need it."