Can I use the jQuery.guid
for my own use? I have elements where I need a unique id attr so I just want to set it to jQuery.guid++
like so:
var guid = jQuery.guid++;
$('<a href="#" id="a' + guid + '">link</a>').appendTo('body');
Is this safe? Will it break any code or plugins?
Although the JavaScript language itself does not have built-in support for generating a UUID or GUID, there are plenty of quality 3rd party, open-source libraries that you can use. The JavaScript library we recommend for generating UUIDs is called (unsurprisingly), uuid . It can generate version 1, 3, 4 and 5 UUIDs.
To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.
You can use this code to generate a Guid:
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function(c)
{
var r = Math.random() * 16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With