2

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 ?

AnyOne
  • 931
  • 2
  • 12
  • 40

2 Answers2

2

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...

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
0

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.

Dan Short
  • 9,598
  • 2
  • 28
  • 53