Skip to content

Instantly share code, notes, and snippets.

@brentsowers1
Created June 10, 2012 23:10
Show Gist options
  • Save brentsowers1/2907639 to your computer and use it in GitHub Desktop.
Save brentsowers1/2907639 to your computer and use it in GitHub Desktop.
jQuery attachment types test case 2
function generate10KRandomClass(attachEventDirectly) {
var generateFunction = function() {
var containerElement = $("#container");
containerElement.html("");
if (!attachEventDirectly) {
// There will be 100 possible classes, call .on for each
for (var i=0; i < 100; i++) {
containerElement.on('click', ".randomClassItem" + i, callbackFunction);
}
}
for (var i=0; i < 10000; i++) {
var element = $('<div id="element' + i + '" class="randomClassItem' + Math.floor(Math.random() * 100) + '"><a href="#">click me</a>&nbsp;</div>');
containerElement.append(element);
if (attachEventDirectly) {
element.click(callbackFunction);
}
}
};
timeAction(this, generateFunction);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment