Created
February 5, 2010 00:36
-
-
Save wombleton/295320 to your computer and use it in GitHub Desktop.
jquery generateId that preserves existing ids and guesses appropriate prefixes, similar to Ext's id()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.extend((function() { | |
var counts = {}; | |
return { | |
generateId: function(prefix) { | |
prefix = (prefix || 'jq') + '-'; | |
counts[prefix] = counts[prefix] || 0; | |
return prefix + counts[prefix]++; | |
} | |
} | |
})()); | |
$.fn.generateId = function() { | |
return this.each(function() { | |
this.id = this.id || $.generateId((this.className.split(' ').shift() || this.tagName.toLowerCase())); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment