Created
May 5, 2015 19:49
-
-
Save ephbaum/98b285048e31bf951307 to your computer and use it in GitHub Desktop.
click click click
This file contains hidden or 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
// test a | |
var $testContainer = $('.test-container'), elem = $( '<p class="test_jquery_click">Test Elem</p>' ), counterArray = []; | |
$testContainer.text(''); | |
for (var i = 50; i >= 0; i--) { $testContainer.append( elem ); } | |
$('p.test').click( function(e) { counterArray.push($(this)); }); | |
$('.test-container > p.test_jquery_click').each(function() {$(this).click();}); | |
console.dir( $testContainer ); | |
//test b | |
var $testContainer = $('.test-container'), elem = $( '<p class="test_jquery_trigger" onclick="$(this).trigger(\'test-click\');">Test Elem</p>' ), counterArray = []; | |
$testContainer.text(''); | |
for (var i = 50; i >= 0; i--) { $testContainer.append( elem ); } | |
$(document).on('test-click', function(e) { counterArray.push($(e.target)); }); | |
$('.test-container > p.test_jquery_trigger').each(function() { $(this).click(); }); | |
console.dir( $testContainer ); | |
// test c | |
var testContainer = document.getElementsByClassName( 'test-container' ), elem = document.createElement( 'p' ), counterArray = [], handle = function(e){ counterArray.push( e.target ); }; | |
testContainer[0].innerHTML = ''; | |
elem.className = 'native_js_click'; | |
elem.textContent = 'Test Elem'; | |
elem.onclick = handle; | |
for (var i = 50; i >= 0; i--) { testContainer.innerHTML += elem; } | |
var testContainerChildren = testContainer.children; | |
for (var j = testContainerChildren.length; j >= 0; j-- ) { testContainerChildren[j-1].click(); } | |
console.dir( testContainer[0] ); | |
// jsperf.com/click-click-click |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment