Created
June 10, 2012 23:07
-
-
Save brentsowers1/2907631 to your computer and use it in GitHub Desktop.
jQuery attachment types test case 1
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
// Some action that triggers generating 10,000 elements | |
function generate10KElements(attachEventDirectly) { | |
var generateFunction = function() { | |
var containerElement = $("#container"); | |
containerElement.html(""); | |
if (!attachEventDirectly) { | |
// This is the magic, all items within the container div that have a CSS class | |
// of sameClassItem get the callbackFunction handler. | |
containerElement.on('click', ".sameClassItem", callbackFunction); | |
} | |
for (var i=0; i < 10000; i++) { | |
var element = $('<div class="sameClassItem" id="element' + i + '"><a href="#">click me</a> </div>'); | |
containerElement.append(element); | |
if (attachEventDirectly) { | |
// The traditional way to attach a handler with jQuery | |
element.click(callbackFunction); | |
} | |
} | |
}; | |
timeAction(this, generateFunction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment