Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using jQuery.guid

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?

like image 280
qwertymk Avatar asked Apr 10 '11 14:04

qwertymk


People also ask

Can JavaScript generate a GUID?

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.

How do I generate a GUID?

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.


1 Answers

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);
});
like image 122
CodeRush Avatar answered Sep 29 '22 11:09

CodeRush