what's the equivalent of this function in javascript:
http://php.net/manual/en/function.uniqid.php
Basically I need to generate a random ID that looks like: a4245f54345
and starts with a alphabetic character (so I can use it as a CSS id)
what's the equivalent of this function in javascript:
http://php.net/manual/en/function.uniqid.php
Basically I need to generate a random ID that looks like: a4245f54345
and starts with a alphabetic character (so I can use it as a CSS id)
All answers here (except phpjs) don't generate unique IDs because it's based on random. Random is not unique !
a simple solution :
It's easy to add dynamic prefix if it's needed. Just change
unique_id_counter
into an array storing counters for each prefixes.I have been using this ...
I use it exactly as I would if it where PHP. Both return the same result.
It's a bit convoluted, but you get the gist I'm sure!
Example: http://jsfiddle.net/Ng4tB/
Try this (Work in php).
Try this for JavaScript::
it is generated on "the same" priciple as PHP's uniqId() - specifically encoded time in microseconds.
Try PHPJS's website, specifically the page for uniqid