jQuery Javascript create unique ID for an Element

Hi Guys,

There are time when you want to create a unique ID on the Fly either from your JQuery plugin or your usual JavaScript Code

Here are couple of ways I use without extending the Object class

First method

Usage

You can use the above method to return uniq id as shown below

Second method

In second method we will use a counter as shown below

Above method use an object with has one property counter and a method get

Usage

Above can be utilized in your code as shown below

I have typed above code directly in this post rather than copy pasting

If you find any error in above method or want to suggest any other method please leave your comments.

Cheers,

 

 

 

 

 

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Speak Your Mind

*

CommentLuv badge