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
if (! idlength) { } for (var i = 0; i < length; i++) { } // one last step is to check if this ID is already taken by an element before else }
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
counter:0, get:function(prefix) { if(!prefix) { prefix = "uniqid"; } if(jQuery("#"+id).length == 0) return id; else } }
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
// if you want to prefix your ID the do this
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,





JC WordPress Coupon Revealer Plugin Pro License
Australian Street Names with City, State and Display Names only, Single Server License
Recent Comments