I would like to have a hashtable of jQuery objects and needs some kind of unique identifier for them.
The DOM representation is just
<tr>
...
</tr>
And I would like to add my jQuery <tr>
objects to a hashtable
hash[$(trObject).guid()] = $(trObject);
How can I uniquely identify a particular jQuery object without extending jQuery?
I know I could write a method
(function() {
var guid = 0;
$.fn.guid = function() {
var node = this[0];
if (node.guid === undefined) {
node.guid = guid++;
}
return node.guid;
};
}());
To do this for me, but I would prefer to know if there is some kind of native standard way to get a string/int hashcode from a jQuery object.
P.S. I don't expect to hit the 32bit integer limit.
No native standard way which I am aware of but there are jquery plugins for this
eg. http://plugins.jquery.com/project/GUID_Helper
UPDATE:
The guid number used by jquery is stored in jquery.guid
Moreover, jquery is not using any native standard method for this. It is also following an approach similar to yours.
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