I was remembering that there was a jquery method which provide unique number for dom elements. It just may for only animated dom objects. Now I couldn't find that method. What is that method ? Is there any another way to provide unique number for elements ?
-
http://stackoverflow.com/questions/226689/unique-element-id-even-if-element-doesnt-have-one – Blazemonger Sep 14 '11 at 12:35
-
May this other stack overflow question help you? http://stackoverflow.com/questions/3298500/unique-identifier-for-html-elements – Arnaud Leymet Sep 14 '11 at 12:35
-
See also: http://forum.jquery.com/topic/return-unique-id-with-jquery-data-elem – Blazemonger Sep 14 '11 at 12:36
2 Answers
I think you may be thinking about the concept of jQuery.expando
. There is an attribute called jQuery.expando
that exists on every page that has jQuery running. It is defined like this:
expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
So for me, on the current page, it is jQuery15209244967177268291
. Any element that has any data stored on it (including event handlers, which are stored as data) has a property with that name. This contains a unique number, which is the key for that element in the global data cache.
For instance, with the global StackExchange inbox on the top left of the screen:
$('.genu')[0].jQuery15209244967177268291 === 29
You can mimic this with $('.genu')[0][jQuery.expando]
; I'm not sure whether you'll get the same number. (Edit: it's not even the same number for me every time.)
Note, however, that not every element has a unique number, only those with data attached to them. This may or may not fit your purposes...

- 233,373
- 50
- 316
- 318
The only thing that looks remotely like what you might be after is the jQuery.unique(), but even that doesn't do what you're suggesting. I would encourage you to update your question to state the purpose for this, as there may be a better way to solve the problem that is prompting you to get unique numbers for each element.

- 9,598
- 2
- 28
- 53